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中停止工作。
有没有简单的方法来清除所有这些? –