Poking around with Reflector reveals that the the interval is hardcoded. Expiry is handled by an internal CacheExpires
class, whose static constructor contains
_tsPerBucket = new TimeSpan(0, 0, 20);
_tsPerBucket
is readonly
, so there can't be any configuration setting that modifies it later.
The timer that will trigger the check for expired items is then set up in CacheExpires.EnableExpirationTimer()
...
DateTime utcNow = DateTime.UtcNow;
TimeSpan span = _tsPerBucket - new TimeSpan(utcNow.Ticks % _tsPerBucket.Ticks);
this._timer = new Timer(new TimerCallback(this.TimerCallback), null,
span.Ticks / 0x2710L, _tsPerBucket.Ticks / 0x2710L);
The calculation of span
ensures that the timer fires exactly on :00, :20, :40 seconds, though I can't see any reason to bother. The method that the timer calls is internal
, so I don't think there's any way to set up your own timer to call it more often (ignoring reflection).
However, the good news is that you shouldn't really have any reason to care about the interval. Cache.Get()
checks that the item hasn't expired, and if it has then it removes the item from the cache immediately and returns null
. Therefore you'll never get an expired item from the cache, even though expired items may stay in the cache for up to 20 seconds.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…