手动清除单个应用程序/网站的ASP.NET服务器缓存?

Fai*_*ins 31 asp.net iis-7 caching clear

如何在给定的应用程序/网站上手动清除ASP.NET服务器缓存(IIS 7),例如在IE中可以清除给定域的浏览器缓存?

Nak*_*nch 45

使用以下命令从缓存中删除所有对象

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

while (enumerator.MoveNext())
{

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

}
Run Code Online (Sandbox Code Playgroud)

此外,它是一个大锤选项,但您可以重新启动整个应用程序,如下所示:

System.Web.HttpRuntime.UnloadAppDomain();
Run Code Online (Sandbox Code Playgroud)

  • 需要将enumerator.Key强制转换为字符串,因为Remove需要字符串,所有键都是字符串 (2认同)

Nik*_*lff 12

我有同样的问题,回收应用程序池帮助了我.我的所有缓存都会立即重新加载.