Thomas
Thomas

Reputation: 34188

How to Invalidate cache data manually in ASP.Net WebForm

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

Answers (2)

Mehdi Souregi
Mehdi Souregi

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

Lloyd
Lloyd

Reputation: 29668

Easiest option available to you - remove it:

cache.Remove(key);

Upvotes: 0

Related Questions