Good Morning
I am trying to integrate the caching mechanism in my current project and wanted to ask on the best practice and questions I have.
My web.config is defined as follows:
<configSections>
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<cachingConfiguration defaultCacheManager="SomeName">
<cacheManagers>
<add expirationPollFrequencyInSeconds="600" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="10" backingStoreName="Null Storage" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="SomeName" />
</cacheManagers>
<backingStores>
<add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Null Storage" />
</backingStores>
</cachingConfiguration>
When I am adding something to the cache, I use the following code:
ICacheManager manager = CacheFactory.GetCacheManager("SomeName");
if (manager.GetData(key) != null && IsCacheEnable)
{
specialChars = (Hashtable)manager.GetData(key);
}
else
{
manager.Add(key, specialChars, CacheItemPriority.Normal, null, new SlidingTime(new TimeSpan(0, 0, CacheExpirySecond)));
}
From the documentation, I can see that items put in the cache via the method Add(string key, object value)
does not expire.
However, I can see that the method Add(string key, object value, CacheItemPriority scavengingPriority, ICacheItemRefreshAction refreshAction, params ICacheItemExpiration[] expirations)
defines a timespan that specifies when the cache will expire
My question is, why should we define the expirationPollFrequencyInSeconds
property in the web.config when we would need to define a timespan again when adding items in the cache using the second Add method? Am i missing something?
Thanks