2011-03-11 63 views

回答

40

使用以下方法来从缓存

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

while (enumerator.MoveNext()) 
{ 

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

} 

同时删除所有对象,这是一个有点大锤的选择,但你可以按如下重新启动整个应用程序:

System.Web.HttpRuntime.UnloadAppDomain(); 
+0

我从来没有见过在httpruntime之前的方法 – 2011-03-11 16:22:42

+0

@Chris Mansic:它在那里。我以前用过它。在这里看看MSDN:http://msdn.microsoft.com/en-us/library/system.web.httpruntime.unloadappdomain.aspx – 2011-03-11 16:24:12

+2

需要将enumerator.Key强制转换为字符串,因为Remove需要string而所有的键都是字符串 – GameSalutes 2015-05-28 19:14:26

12

我同样的问题,并且回收应用程序池帮助了我。我所有的缓存立即重新加载,因为我想要的。