I have a class that holds valid licenses for a user and every 15 minutes it is "validated" to ensure the current licenses are valid and add/remove any that may have changed.
Currently, this is accessed in my ApplicationController, which every other controller in the application inherits from, so that whenever the user performs any operations, it ensures they have the valid licenses / permissions to do so.
Licensing Model:
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...
}
Validation Process: (occurs inside the Initialize() method of the ApplicationController)
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;
}
Summary:
As you can see, this process currently uses the Session to store the LicenseModel, however I was wondering if it might be easier / more-efficient to use the Cache to store this. (Or possibly the OutputCache?) and how I might go about implementing it.