Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching Expiration not working as expected

I'm using the HttpContext.Current.Cache to cache expensive data queries with a CacheItemUpdateCallback.

The idea is that the user has to load the data once and then the updatecallback keeps the object updated every 30 minutes.

This is how I insert / overwrite the cache:

HttpContext.Current.Cache.Insert(cacheID, cachedObject, null,
                                  expiryTimeStamp,
                                  Cache.NoSlidingExpiration,
                                  updateCallBack);   

For test reasons I set the expiration date like this (update every 20 seconds):

var expiryTimeStamp = DateTime.Now.Add(new TimeSpan(0, 0, 20));

This all works fine. That means, it's updating the expensive object every 20 seconds - but only for about 25 minutes. Then the trigger 'updateCallBack' is not called anymore!

I guess the problem is that the IIS disposes the cache so the callback 'CacheItemUpdateCallBack' is not fired anymore...But that is only a guess.

That leads me to my question:

Is there any setting I have to set in app.config or in the IIS? Or what am I doing wrong?

EDIT: Furthermore, I don't understand why the Insert overload with CacheItemUpdateCallback does not have a parameter CacheItemPriority. However, the overload with CacheItemRemovedCallback does have a priority parameter. Maybe, if I could set the CacheItemPriority to 'High' it would already solve my issue.

EDIT: I found the issue: There is an idle timeout property for each application pool which was set to 20 minutes.

like image 325
Fabian Bigler Avatar asked Jan 26 '16 12:01

Fabian Bigler


1 Answers

The idle timeout of the application pool was set to 20 minutes (as per default). And because it was a test instance, there was no user keeping the website alive.

like image 59
Fabian Bigler Avatar answered Oct 23 '22 13:10

Fabian Bigler