Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache.NoSlidingExpiration in ASP - when is it reset?

I have found an answer to a similar question (System.Web.Caching.Cache.NoSlidingExpiration in asp.net c#) and followed the links, but I need more specific information I cannot find.

NoSlidingExpiration does not reset when you 'access' it. But, does that mean when you read it? Or also when you write it?

For example, if I do

Cache.Insert("mykey", 42, null, DateTime.Now.AddMinutes(20), System.Web.Caching.Cache.NoSlidingExpiration);

and then 10 minutes later, I do:

Cache.Insert("mykey", 42, null, DateTime.Now.AddMinutes(20), System.Web.Caching.Cache.NoSlidingExpiration);

again, will the expiry be adjusted?

Thanks!

like image 869
Jordan Morris Avatar asked Sep 29 '11 08:09

Jordan Morris


1 Answers

According to the MSDN doc on Cache.NoSlidingExpiration

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.

That means when you call Add or Insert, whatever the absoluteExpiration value you have given in that call will be used to expire that item. So in your example:

DateTime.Now.AddMinutes(20)

means the item will be reset after 20 minutes.

like image 151
Jason Evans Avatar answered Oct 05 '22 23:10

Jason Evans