缓存值过期的轮询问题

Topics: Caching Application Block
Feb 22, 2013 at 3:03 AM
   <add name="cache1" 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="inMemory" />
这里设置轮询时间为60秒
cacheMarager.Add(key, val, CacheItemPriority.Normal, null, new AbsoluteTime(TimeSpan.FromSeconds(10)));
设置过期时间为当前时间后10秒?那么缓存值val是在60秒后过期还是在10秒后呢?
我理解的是60秒,因为系统设置是60秒才检查一次,虽然10秒的时候过期了,但是在第60秒时才会检查是否过期
Feb 22, 2013 at 5:11 AM
Edited Feb 22, 2013 at 5:12 AM
expirationPollFrequencyInSeconds="60" tells the caching block to check the cache for expired items to remove every 60 seconds.

When adding items to the cache you can specify the expiration policy. In your example above, an expiration of AbsoluteTime(TimeSpan.FromSeconds(10)) means that 10 seconds after the item is added to the cache it will expire. After it expires it will either be removed from the cache on the next attempt to access that cache item or the next time the background expiration cycle runs.

You can read about the caching block in Chapter 5 - A Cache Advance for your Applications of the Developer's Guide.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to