C # Cache expiration does not work

I add the following value to the cache:

HttpContext.Cache.Insert( "ClientId", clientid, null, DateTime.UtcNow.AddYears(1), TimeSpan.Zero ); 

I do not want the cache to expire, so I set the date in a year ( DateTime.UtcNow.AddYears(1) ), but after 30 minutes there is no more cached value.

+4
source share
3 answers

I do not know why your code does not work, but if you do not want to expire the value, you can use HttpContext.Current.Application.Add("ClientID", value)

0
source

You need to use the Application if you want the elements to remain forever, and not the cache. The cache does not guarantee that the item will be saved at the time you specify if there is memory pressure. Also, judging by the 30 minutes that you mentioned, there is a possibility that your application domain will be reused if there is no user activity on the site.

+2
source

From MSDN:

If you are using absolute expiration, the slideExpiration parameter must be NoSlidingExpiration .

+2
source

All Articles