Default duration of Cache.Insert in ASP.NET

12,836

Solution 1

"Never", that is, as soon as memory is low and ASP.NET Cache thinks it has something more important to keep.

Solution 2

This will insert the object without an explicit expiration set. This means the object will not automatically be removed from the cache, unless the runtime decides to remove stuff from the cache due to high memory usage.

Calling this overload is the same as calling

Cache.Insert(
  key, value,
  null,                     /*CacheDependency*/
  NoAbsoluteExpiration,     /*absoluteExpiration*/
  NoSlidingExpiration,      /*slidingExpiratioin*/
  CacheItemPriority.Normal, /*priority*/
  null                      /*onRemoveCallback*/
);

BTW: you can use .NET reflector to find out such things.

Share:
12,836

Related videos on Youtube

cduhn
Author by

cduhn

I enjoy running my data processing boxes at a 5-minute load average of 77. Keep it hot and off heap.

Updated on September 15, 2020

Comments

  • cduhn
    cduhn over 3 years

    If I have the following line, when should I expect the cache to expire?

    System.Web.HttpRuntime.Cache.Insert("someKey", "Test value");
    
  • Nirlep
    Nirlep over 14 years
    Is restarting of iis/application pool under which web site is running will cause object to be removed from cache? In short, is there any connection between iis/application pool and cache?
  • realMarkusSchmidt
    realMarkusSchmidt over 14 years
    Yes, all your cache items will be gone if your application pool or your application (change in BIN folder or web.config) restarts, as long as you don't use any out-of-process cache provider. So it actually is just what it is: a cache. Don't use it for anything else. You can never make assumptions on what is in there (only what should not be in there anymore).