2
我有一个类为用户保存有效的许可证,每15分钟对其进行“验证”以确保当前许可证有效并添加/删除任何可能已更改的许可证。在MVC2中使用高速缓存存储
目前,这是在我的ApplicationController中,其应用程序中的所有其他控制器从继承,所以,每当用户执行任何操作,它可以确保他们有有效牌照/许可这样做访问。
许可模式:
public class LicenseModel
{
public DateTime LastValidated { get; set; }
public List<License> ValidLicenses { get; set; }
public bool NeedsValidation
{
get{ return ((DateTime.Now - this.LastValidated).Minutes >= 15);}
}
//Constructor etc...
}
验证过程:(发生ApplicationController中的Initialize()方法内)
LicenseModel licenseInformation = new LicenseModel();
if (Session["License"] != null)
{
licenseInformation = Session["License"] as LicenseModel;
if (licenseInformation.NeedsValidation)
licenseInformation.ValidLicenses = Service.GetLicenses();
licenseInformation.LastValidated = DateTime.Now;
Session["License"] = licenseInformation;
}
else
{
licenseInformation = new LicenseModel(Service.GetLicenses());
Session["License"] = licenseInformation;
}
总结:
正如您所看到的,此进程当前使用会话来存储LicenseModel,但是我想知道使用缓存来存储它可能更容易/更高效。 (或者可能是OutputCache?)以及我如何去实现它。