更改ASP.NET缓存项过期的频率是多少? [英] Changing frequency of ASP.NET cache item expiration?

查看:181
本文介绍了更改ASP.NET缓存项过期的频率是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,ASP.NET缓存项检查(也可能删除)每20秒(奇怪的是每次HH:MM:00,HH:MM:20和HH:MM:40)。我花了大约15分钟看如何改变这个参数没有任何成功。我也试着设置在web.config中以下,但它并没有帮助:

I noticed that the ASP.NET cache items are inspected (and possibly removed) every 20 seconds (and oddly enough each time at HH:MM:00, HH:MM:20 and HH:MM:40). I spent about 15 minutes looking how to change this parameter without any success. I also tried to set the following in web.config, but it did not help:

<cache privateBytesPollTime="00:00:05" />

我不想做任何疯狂的,但它会是很好,如果它是,比方说5秒而不是20的,或我的应用程序至少10

I’m not trying to do anything crazy, but it would be nice if it was, say, 5 seconds instead of 20, or at least 10 for my application.

推荐答案

与反射闲逛显示,间隔为硬codeD。到期由内部处理 CacheExpires 类,它的静态构造函数中包含

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 只读,所以不能有任何配置设置以后修改它。

_tsPerBucket is readonly, so there can't be any configuration setting that modifies it later.

这将触发对过期的项目检查计时器,然后成立了 CacheExpires.EnableExpirationTimer() ...

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

跨度的计算确保定时器触发正是上:00:20:40秒,虽然我看不到任何理由打扰。计时器调用该方法内部,所以我不认为有任何的方式来建立自己的计时器,更经常调用它(忽略反射)。

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).

不过,好消息是,你真的不应该有任何理由关心的间隔。 Cache.Get()检查该项目尚未到期,如果有那么它会立即从缓存中删除的项目,并返回。因此,你永远不会从缓存中得到过期的项目,即使已过期的项目可能会留在高速缓存最多20秒。

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.

这篇关于更改ASP.NET缓存项过期的频率是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆