Reputation: 5242
I'm storing values into HttpContext.Current.Cache
using the Insert
method:
HttpContext.Current.Cache.Insert(key, value, null, DateTime.Now.AddMinutes(1440), TimeSpan.Zero);
In my mind this should store the value in the cache in 1440 minutes. But somehow the cache gets cleared and the key doesn´t exist anymore. The last time I checked this the cache was saved in about 30 minutes.
Could the cache be cleared somehow? If the AppPool is recycled or something like that?
Upvotes: 1
Views: 1393
Reputation: 1258
Are you sure that piece of code is executed? Setting both AbsoulteExpiration
and SlidingExpiration
is illegal in Cache.Insert
. Your code should throw ArgumentException
if executed.
See this link.
Proper usage would be
HttpContext.Current.Cache.Insert(key, item, null, dateExpiration, Cache.NoSlidingExpiration);
Use Cache.NoSlidingExpiration
if you want AbsoluteExpiration
of 1440 minutes.
HttpContext.Current.Cache.Insert(key, value, null, DateTime.Now.AddMinutes(1440), Cache.NoSlidingExpiration);
Hope this helps.
Upvotes: 1
Reputation: 693
Yes, the cache is stored in memory until the process is stopped and hence restarting / resetting IIS or Recycling the App Pool would clear the cache. If it is a local host, building the application will also clear the cache.
Upvotes: 1