Manually clear ASP.NET server cache for a single application/web site?

前端 未结 2 1994
失恋的感觉
失恋的感觉 2021-01-03 18: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?

2条回答
  •  情歌与酒
    2021-01-03 18:52

    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();
    

提交回复
热议问题