I'm trying to use MemoryCache in .Net 4.5 to store an object for 1 month (absolute expiration - 1 month from when the cache is created).
Problem - The cache seems to expire within a day - sometimes within a few hours, in fact.
Code Snippet
// Setting the cache with absolute expiration time of 1 month:
string objName = "myObj";
MemoryCache memCache = MemoryCache.Default;
memCache.Add(tokenID, myObj, DateTimeOffset.UtcNow.AddMonths(1));
// Accessing the cache later
MemoryCache getCache = MemoryCache.Default;
getCache.Get(tokenID);
Questions
Thank you so much!
Check the IIS AppPool setting you are using for your web application. Under Advanced Settings, there is a setting for Idle Time-out (minutes). If your site is idle for longer that this period, the worker process is shut down.