33

How can I manually clear ASP.NET server cache (IIS 7) on a given application/website, like what can be done in IE to clear browser cache for a given domain?

1
  • Would you be able to mark the answer as a real answer? Thanks :) Feb 19, 2016 at 4:55

2 Answers 2

49

Use the following to remove all objects from the cache

IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator();

while (enumerator.MoveNext())
{

    HttpContext.Current.Cache.Remove((string)enumerator.Key);

}

Also, it is a bit of a sledgehammer option but you can restart the entire application as follows:

System.Web.HttpRuntime.UnloadAppDomain();
3
  • I've never seen that method on httpruntime before Mar 11, 2011 at 16:22
  • @Chris Mansic: It's there. I've used it before. Take a look here at MSDN: msdn.microsoft.com/en-us/library/… Mar 11, 2011 at 16:24
  • 2
    Need to cast enumerator.Key to a string since Remove takes string and all keys are strings May 28, 2015 at 19:14
12

I had the same problem, and recycling the application pool helped me. All my caches immediately reloaded as I wanted.

Ways of recycling the application pool are described here.

1
  • 1
    You should add a path on How to recycling the Pool. Anyway, could find here
    – fiskolin
    May 5, 2020 at 17:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.