1

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?

2 Answers 2

2
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]);
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

0

Easiest option available to you - remove it:

cache.Remove(key);

1 Comment

@Thomas Ahh yes I didn't see that in the title, though you should make it clearer in the body. However there's no way to do it manually I'm afraid, not without again writing some kind of page that lets you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.