Reputation: 363
I'm using caching application block on my application. The configuration file looks like this:
<cachingConfiguration defaultCacheManager="Cache Manager">
<cacheManagers>
<add name="ParamCache" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="10" backingStoreName="NullBackingStore"/>
</cacheManagers>
<backingStores>
<add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="NullBackingStore"/>
</backingStores>
</cachingConfiguration>
I though that the expirationPollFrequencyInSeconds attribute will control the expiration of the values stored in the cache, so if I'll try fetching a value that the cache stores 60 seconds or more, it would be fetched from the DB and not the cache. However with this configurations I see that the value is still fetching from the cache for about 5 minutes and only then gets the updated value from the DB.
What am I missing?
Upvotes: 2
Views: 5413
Reputation: 893
You havent actually set a timeout policy on your cache. The expirationPollFrequencyInSeconds
attribute does what it says, it polls the cache every 60 seconds.
The default behaviour in your cache at the moment is, I believe, to store up to 1000 elements in the cache, thereafter to start scavenging memory by remove the 10 least used cache items. It will check each item every 60 seconds, as you have set it to.
You would need to do this somewhere in your code, or you could configure it in your config file, which is what I would suggest.
AbsoluteTime absTime = new AbsoluteTime(TimeSpan.FromMinutes(1));
cacheManager.Add("CacheObject", cachedInformation, CacheItemPriority.Normal, null, absTime);
Here is a good CodeProject article which describes how to use it properly, including what looks like an exact copy of your code.
Upvotes: 1
Reputation: 363
Found the problem. The expirationPollFrequencyInSeconds parameter does not affect the item expiration in the cache, just the frequency of the cleanup of expired items.
Actually the expiration time is set when the item is added to the cache, in my case it was set to 5 minutes...
Upvotes: 3