Default duration of Cache.Insert in ASP.NET

2019-04-05 02:03发布

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

System.Web.HttpRuntime.Cache.Insert("someKey", "Test value");

2条回答
forever°为你锁心
2楼-- · 2019-04-05 02:33

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

查看更多
疯言疯语
3楼-- · 2019-04-05 02:35

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.

查看更多
登录 后发表回答