1
ASP.Net MVC 3中的ViewEngine緩存添加或移動視圖時導致錯誤的視圖和部分視圖的物理路徑文件在我的生產環境中。有沒有辦法在運行時清除緩存?我在網上發現一篇文章說緩存存儲在HttpContext.Cache中,但我不確定它是哪個入口。如何清除ASP.Net MVC中ViewEngine使用的視圖文件位置緩存3
ASP.Net MVC 3中的ViewEngine緩存添加或移動視圖時導致錯誤的視圖和部分視圖的物理路徑文件在我的生產環境中。有沒有辦法在運行時清除緩存?我在網上發現一篇文章說緩存存儲在HttpContext.Cache中,但我不確定它是哪個入口。如何清除ASP.Net MVC中ViewEngine使用的視圖文件位置緩存3
這裏是由Razor視圖引擎使用的密鑰:
// System.Web.Mvc.VirtualPathProviderViewEngine
private string CreateCacheKey(string prefix, string name, string controllerName, string areaName)
{
return string.Format(CultureInfo.InvariantCulture, ":ViewCacheEntry:{0}:{1}:{2}:{3}:{4}:", new object[]
{
base.GetType().AssemblyQualifiedName,
prefix,
name,
controllerName,
areaName
});
}
因此,舉例來說,如果你想清除Index
視圖的緩存位置Home
控制器,你會從HttpContext.Cache
刪除以下注冊表項:
HttpContext.Cache.Remove(":ViewCacheEntry:System.Web.Mvc.RazorViewEngine, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35:View:Index:Home::");
和用於_LogOnPartial.cshtml
部分:
HttpContext.Cache.Remove(":ViewCacheEntry:System.Web.Mvc.RazorViewEngine, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35:Partial:_LogOnPartial:Home::");
您應該明白,您正在使用完全沒有記錄的功能,可以在不做任何通知的情況下進行更改,並且您的代碼可能會在未來版本的ASP.NET MVC中停止工作。
有沒有簡單的方法來清除所有這些? –