After 15 minutes, the next cache expires?

_cache.Insert(cacheKey, userList, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 15, 0), CacheItemPriority.High, null); 

My code above does not expire through the cache after 3 minutes, the userList object retrieves data from the database that has been updated, but the cache does not expire after 15 minutes.

What's wrong?

+4
source share
2 answers

You explicitly set the cache to never end using Cache.NoAbsoluteExpiration . Instead, you want to use Cache.NoSlidingExpiration :

When used, this field sets the slidingExpiration parameter to TimeSpan.Zero , which has a constant value of zero. The cached item expires according to the absoluteExpiration parameter associated with the call to the Insert or Add method.

+5
source

You drive 15 minutes to the sliding expiration parameter: http://msdn.microsoft.com/en-us/library/05kd8d77.aspx

The interval between the time of the last access to the inserted object and the expiration time of this object. If this value is equivalent to 20 minutes, the object will expire and will be deleted from the cache 20 minutes after its last access. If you use rolling completion, the absoluteExpiration parameter must be NoAbsoluteExpiration.

If your cached item is accessible more often than every 15 minutes, it will never expire.

 _cache.Insert( cacheKey, userList, null, new TimeSpan(0, 15, 0), Cache.NoSlidingExpiration, CacheItemPriority.High, null); 

The item will expire after 15 minutes.

+3
source

Source: https://habr.com/ru/post/1438999/


All Articles