我使用的System.Web.Caching.Cache 通过我的网站使用的组件。我已经设置了一些关键到期(绝对过期)为10秒(只用于调试)。我也设置在关键去除回调。
I am using System.Web.Caching.Cache in an assembly used by my website. I have set some key expiration (absolute expiration) to be 10 seconds (just for debugging). I have also set a callback upon key removal.
问题是,我看到缓存像20秒后刷新得到,而不是10。
The problem is that I see that the cache is getting refreshed after something like 20 seconds and not 10.
我使用 HttpRuntime.Cache 这一点。
有关这是为什么发生的任何建议?
Any suggestion for why is that happening ?
我想表现出code样品,它可以更加清楚:
I would like to show a code sample, which can shed more light:
public void OnUpdate(string key , CacheItemUpdateReason reason , out object expensiveObject , out CacheDependency dependency , out DateTime absoluteExpiration , out TimeSpan slidingExpiration) { using (StreamWriter sw = new StreamWriter(@"C:\temp\foo.txt",true)) { sw.WriteLine("Updated Cache at " + DateTime.UtcNow); } expensiveObject = 11; dependency = null; absoluteExpiration = DateTime.UtcNow.AddSeconds(3); slidingExpiration = Cache.NoSlidingExpiration; } protected void Page_Load(object sender, EventArgs e) { log.WriteInfo("Updated Cache", MethodBase.GetCurrentMethod()); Page.Cache.Insert("foo", (object)11, null, DateTime.UtcNow.AddSeconds(10), Cache.NoSlidingExpiration, new CacheItemUpdateCallback(OnUpdate)); }在这里,我用 Page.Cache 。更新应该是每3秒。实际上它是每40秒执行,如下面的打印输出显示:
Here, i used Page.Cache. The update should be every 3 seconds. Actually it is performed every 40 seconds, as the below printout shows:
在2011年1月28日上午01时38分20秒更新缓存在2011年1月28日上午1时38分四十零秒更新缓存在2011年1月28日上午01时39分零零秒更新缓存在2011年1月28日上午1点39分20秒更新缓存在2011年1月28日上午01时39分四十零秒更新缓存在2011年1月28日上午一时40分00秒更新缓存在2011年1月28日上午1时40分20秒更新缓存在2011年1月28日上午01时40分40秒更新缓存在2011年1月28日上午01时41分00秒更新缓存在2011年1月28日上午1点41分20秒更新缓存在2011年1月28日上午01时41分四十秒更新缓存在2011年1月28日上午01点42分00秒更新缓存在2011年1月28日上午1时42分二十秒更新缓存在2011年1月28日上午一时42分40秒更新缓存
这可能是什么问题?
推荐答案的内部缓存过期计时器只激发每20秒。
The internal cache expire timer only fires every 20 seconds.
我反映到 System.Web.Caching.CacheExpires
但后来发现它已经是SO
But then found it already is on SO
Changing ASP.NET缓存项过期的频率是多少?
更多推荐
的System.Web.Caching.Cache似乎并没有刷新自己的时间呢?
发布评论