Reputation: 34188
Suppose I cache data as per below for 10 minutes:
cache.Insert(
key,
dt,
null,
new TimeSpan(0, 10, 0),
Cache.NoSlidingExpiration,
CacheItemPriority.High,
null);
How do I invalidate the cache before 10 minutes?
Upvotes: 1
Views: 1718
Reputation: 3265
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]);
}
}
Upvotes: 2