PERMANENTLY add something to Cache

Posted on 2005-04-07
Last Modified: 2010-04-07
How do I add something that will live in the Cache permanently?
This object will be added to cache when application is started and should exist until the application is closed.

Question by:smacca
    LVL 14

    Expert Comment


    You can set a datetime to expire ... make it always set to something really far out like 20 years from now and that should work ... I'm sure other methods could be used too.
    LVL 5

    Expert Comment

    You can use the "old fashioned way", application("aNameForYourObject")=[your object]
    LVL 26

    Accepted Solution

    use global.asax file's application on_start event to set the cache .. and as dfu23 has suggested .. set the expiry to 20 years or so ... also set the priority to "NotRemovable" so that it never gets removed from the cache
    this will add a dataset to the cache for 20 years and it will never get removed until the application is restarted .. ...
            Cache.Insert("MyKey", MyDataset, null, DateTime.Now.AddYears(20), TimeSpan.Zero, Caching.CacheItemPriority.NotRemovable)

    and if u add the above line in global.asax onstart .. it will ensure that it is always re-created when the application starts ...


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now