[英]How to Invalidate cache data manually in ASP.Net WebForm
Suppose I cache data as per below for 10 minutes: 假设我按照以下内容缓存数据10分钟:
cache.Insert(
key,
dt,
null,
new TimeSpan(0, 10, 0),
Cache.NoSlidingExpiration,
CacheItemPriority.High,
null);
How do I invalidate the cache before 10 minutes? 我如何在10分钟之前使缓存无效?
您可以使用的最简单的选项-将其删除:
cache.Remove(key);
public void ClearApplicationCache()
{
List<string> keys = new List<string>();
IDictionaryEnumerator enumerator = Cache.GetEnumerator();
while (enumerator.MoveNext())
{
keys.Add(enumerator.Key.ToString());
}
for (int i = 0; i < keys.Count; i++)
{
Cache.Remove(keys[i]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.