早上好
我正在尝试将缓存机制集成到我当前的项目中,并想询问我的最佳实践和问题。
我的 web.config 定义如下:
<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>
当我向缓存中添加内容时,我使用以下代码:
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)));
}
从文档中,我可以看到通过该方法放入缓存的项目Add(string key, object value)
不会过期。但是,我可以看到该方法Add(string key, object value, CacheItemPriority scavengingPriority, ICacheItemRefreshAction refreshAction, params ICacheItemExpiration[] expirations)
定义了一个时间跨度,该时间跨度指定缓存何时到期
expirationPollFrequencyInSeconds
我的问题是,当使用第二个 Add 方法在缓存中添加项目时需要再次定义时间跨度时,为什么要在 web.config 中定义属性?我错过了什么吗?谢谢