下面的代码有问题。我有以下代码,
if (HttpRuntime.Cache[cacheKey] == null)
{
AddTask(cacheKey, JsonConvert.SerializeObject(result), 60 * 30);
}
r = JsonConvert.DeserializeObject<Result>(HttpRuntime.Cache[cacheKey].ToString());
HttpRuntime.Cache[cacheKey] = JsonConvert.SerializeObject(r);
private static void AddTask(string key, string value, int seconds)
{
HttpRuntime.Cache.Insert(key, value, null,
DateTime.Now.AddSeconds(10), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(CacheItemRemoved));
}
public static void CacheItemRemoved(string k, object v, CacheItemRemovedReason r)
{
}我所做的只是简单地添加和更新缓存(如果存在的话)。10秒后我想检查一下。但我的CacheItemRemoved回调从未打过电话。
发布于 2016-05-25 06:00:13
更新缓存时使用
HttpRuntime.Cache[cacheKey] = JsonConvert.SerializeObject(r);然后缓存时间重置为默认时间。现在,我不再使用字符串,而是使用对象实例,而不更新cache.its。
notification = HttpRuntime.Cache[cacheKey] as Notification;
HttpRuntime.Cache.Insert(key, notificationResult , null,
DateTime.Now.AddSeconds(10), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(CacheItemRemoved));https://stackoverflow.com/questions/37390203
复制相似问题