是否存在强制HttpContext的Cache集合中所有条目到期的方法或其他内容?
答案 0 :(得分:18)
尝试这样的事情:
var enumerator = HttpRuntime.Cache.GetEnumerator();
Dictionary<string, object> cacheItems = new Dictionary<string, object>();
while (enumerator.MoveNext())
cacheItems.Add(enumerator.Key.ToString(), enumerator.Value);
foreach (string key in cacheItems.Keys)
HttpRuntime.Cache.Remove(key);
答案 1 :(得分:0)
如何更新缓存到期?
protected void btnClearCache_Click(object sender, EventArgs e)
{
var enumerator = HttpRuntime.Cache.GetEnumerator();
while (enumerator.MoveNext())
HttpRuntime.Cache.Insert(enumerator.Key.ToString(), enumerator.Value,
null, DateTime.Now , Cache.NoSlidingExpiration);
}