Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will the following cached item expire after 15 minutes?

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

My code above doesn't seem to be expiring the cache after 3 minutes, the userList object pulls data from the database that was updated, but the cache doesn't expire it after 15 minutes.

What is wrong?

like image 294
loyalflow Avatar asked Feb 19 '23 21:02

loyalflow


1 Answers

You are explicitly setting the cache to never expire by using Cache.NoAbsoluteExpiration. You want to use Cache.NoSlidingExpiration instead:

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

like image 173
Andrew Hare Avatar answered Mar 03 '23 14:03

Andrew Hare