【发布时间】:2010-01-22 23:18:43
【问题描述】:
我有一个包含以下属性的类:
public Dictionary<string, int> CommentCounts {
get {
string cacheKey = "CommentCounts";
HttpContext c = HttpContext.Current;
if (c.Cache[cacheKey] == null) {
c.Cache.Insert(cacheKey, new Dictionary<string, int>(), null, DateTime.UtcNow.AddSeconds(30), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, null);
c.Trace.Warn("New cached item: " + cacheKey);
}
return (Dictionary<string, int>)c.Cache[cacheKey];
}
set {
HttpContext.Current.Cache["CommentCounts"] = value;
}
}
似乎 Trace 语句只运行一次,而不是在 Cache 项过期后每 30 秒运行一次。我可以让它刷新缓存项的唯一方法是创造一个代码机会并重建项目,这显然不太理想。
我错过了什么?提前谢谢...
【问题讨论】: