Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6379535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:09:03+00:00 2026-05-25T02:09:03+00:00

I have a class that holds valid licenses for a user and every 15

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:09:04+00:00Added an answer on May 25, 2026 at 2:09 am

    The cache would definitely make more sense if the licenses are used application wide and are not specific to any user session. The cache can handle the 15 minute expiration for you and you will no longer need the the NeedsValidation or LastValidated properties on your LicenseModel class. You could probably do away with the model all together and just store the List of valid licenses like so:

    if (HttpContext.Cache["License"] == null)
    {
        HttpContext.Cache.Insert("License",Service.GetLicenses(), null,
        DateTime.Now.AddMinutes(15), Cache.NoSlidingExpiration);
    }
    
    var licenses = HttpContext.Cache["License"] as List<License>;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class Team that holds a generic list: [DataContract(Name = TeamDTO, IsReference
I have a private class variable that holds a collection of order items: Private
I have a class includes.vb that holds some variables (sharing them with other pages)
I have an abstract base class that holds a Dictionary. I'd like inherited classes
I have a class in C++ that I can't modify. However, that class holds
I have a simple class that essentially just holds some values. I have overridden
I have this small class called City that simply holds some information about a
I have a specialized list that holds items of type IThing : public class
I have a class that holds a dictionary of parameters: public class Parameter :
If I have a class that holds one or several lists, is it better

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.