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 8021371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:57:37+00:00 2026-06-04T21:57:37+00:00

I am trying to implement caching in my program. I have a web application

  • 0

I am trying to implement caching in my program. I have a web application that provides user access to some learning courses.When the user logs on I authenticate him from our database. Now, if access a different course from the list I don’t want to go back to the database. Instead I want to store the value in cache for lets say 20 mins. The program should
1) Authenticate the user, and let him access the course. If he changes the course the program should look in cache. if the user id exists let him access the course without going back to server.
2) Provide a mechanism, that if after 20 minutes the user is still on the system, automatically update the time.so, that the user is not logged off.
I tried something like this

Cache ch = new Cache();
ch.Add("key","value);

but I get null refernece exception in 2nd statement. I have never worked with caching before so will appreciate any pointers.

  • 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-06-04T21:57:38+00:00Added an answer on June 4, 2026 at 9:57 pm

    Well this is how I use it:

    /// <summary>
    /// Get Data
    /// </summary>
    /// <returns>data</returns>
    public static ElementOut GetData()
    {
        //function return value
        ElementOut functionReturnValue = new ElementOut();
    
        try
        {
            string key = "data";
            if (HttpRuntime.Cache[key] == null)
            {
                //fetch data
                var data = CreateBLLAdapter().GetData();
    
                //validate data
                if (data == null) throw new Exception("data is empty!");
    
                //set cache to 12 hours
                DateTime timeToExpire = DateTime.Now.AddHours(12);
    
                //set cache
                HttpRuntime.Cache.Insert(key, data, null, timeToExpire, Cache.NoSlidingExpiration);
            }
    
            //set return from cache
            functionReturnValue = (ElementOut)HttpRuntime.Cache[key];
    
        }
        catch (Exception ex)
        {
            //Log.WriteServerErrorLog(ex);
        }
    
        return functionReturnValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement some simple caching into my application and I'm having some
I'm trying to implement some kind of caching in a PHP script that will
I am trying to implement a web application with Caching features.The reason I need
I am trying to implement caching in .Net such that the cached data is
Trying to implement the following behavior on an iPad. I have a map-centric application
when trying to implement an Aspect, that is responsible for catching and logging a
im trying to implement some behaviors when a mapview element scrolls... by coding a
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been
I'm implementing a PHP script which will need some caching capabilities. I'm trying to
I am trying to implement caching using jQuery UI autocomplete. I am using jQuery

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.