Search code examples
c#cachingmemorycacheobjectcache

CacheItemPolicy - SlidingExpiration "Accessed" rules?


From http://msdn.microsoft.com/en-us/library/system.runtime.caching.cacheitempolicy.slidingexpiration(v=vs.110).aspx ...

"A span of time within which a cache entry must be accessed before the cache entry is evicted from the cache. The default is NoSlidingExpiration, meaning that the item should not be expired based on a time span."

What exactly is 'accessed' ? Does that mean if I hit the cached item like:

var object = cache["cachekeyname"];

It's considered to be 'accessed' ?

Or would it only be considered accessed if I actually modify the cached item?


Solution

  • it does mean that the cache is accessed if the following code is called:

    var object = cache["cachekeyname"];
    

    Therefore if the piece of code or functionality containing the above code snippet is not called within X time since you put the object into the cache or it was last accessed it will be removed from the cache.