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:
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();
回答2:
I had the same problem, and recycling the application pool helped me. All my caches immediately reloaded as I wanted.