C# Microsoft企业库-缓存机制过期

C# Microsoft企业库-缓存机制过期,c#,caching,enterprise-library-5,C#,Caching,Enterprise Library 5,早上好 我正在尝试将缓存机制集成到我当前的项目中,并想询问我的最佳实践和问题 My web.config的定义如下: <configSections> <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrar

早上好

我正在尝试将缓存机制集成到我当前的项目中,并想询问我的最佳实践和问题

My 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>
从文档中,我可以看到通过方法
Add(字符串键,对象值)
放入缓存的项不会过期。 但是,我可以看到方法
Add(字符串键、对象值、CacheItemPriority清除优先级、ICacheItemRefreshAction refreshAction、params ICacheItemExpiration[]expirations)
定义了一个指定缓存何时过期的时间跨度

我的问题是,当使用第二个Add方法在缓存中添加项时,我们需要再次定义时间跨度时,为什么要在web.config中定义
expirationPollFrequencyInSeconds
属性?我错过什么了吗?
谢谢

如果我错了,请纠正我

我们在
Add()
方法中指定的
icacheitemfiration
(在本例中)实际上定义了将应用于要添加到缓存中的项的过期策略。在我们的例子中,我们使用了
SlidingTime
expiration策略。假设我们将滑动时间设置为10秒。这意味着,如果连续10秒未访问该项目,则该项目将被标记为过期。当我们需要在有多个请求进入该项时保持该项活动时,这非常有用。作为补充说明,我们还有其他过期策略,如
绝对时间
文件相关性
永不过期

我们需要了解,当一个项目过期时,它仍然存在于散列中,直到后台调度程序删除该项目(取决于后台调度程序将检查其过期的过期策略)。为
expirationPollFrequencyInSeconds
设置值时,我们定义后台计划程序执行和分析哈希以删除已过期项目的时间间隔(根据该项目上定义的过期策略)

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)));
}