Our application adds objects to the cache using the following
int cacheTimeout = 5; // Default 5 minute timeout
if(ConfigurationManager.AppSettings["CacheTimeout"] != null)
{
cacheTimeout = Convert.ToInt32(ConfigurationManager.AppSettings["CacheTimeout"].ToString());
}
_cache.Insert(Key, CacheItem, null, DateTime.MaxValue, new TimeSpan(0, cacheTimeout, 0));
Our manager is concerned about possible caching issues and wants to know, what happens if you insert an object with a 0 length time span.
I think the object will be immediately deleted. Right or wrong?
Answer is “Wrong”.
When inserted into the cache with the absolute expiration set to NoAbsoluteExpiration and the sliding expiration set to new TimeSpan(0,0,0), the callback is not fired immediately. I didn’t wait to see when it would fire, if ever – maybe it’s 20 minutes, maybe it’s never.
So changed the code to this:
That way if we do have caching problems we can update web.config to set the cache time out to 0 and have a 1 second expiration.