OutputCache 通过 MVC 3 应用程序中的操作刷新缓存
在我们正在构建的 MVC 应用程序的许多操作中,我们使用 OutputCache,如下所示:
[OutputCache(Duration = 3600, VaryByCustom = "language")]
public ActionResult SomeAction()
{
//Action..
}
因此,我想要一个可以手动刷新所有这些缓存的操作:
public ActionResult RefrescarCache()
{
var keys = HttpContext.Cache.Cast<DictionaryEntry>().ToList();
keys.ForEach(k => HttpContext.Cache.Remove(k.Key.ToString()));
ViewBag.operationResult= "The cache was flushed succesfully!";
return View();
}
事实是,它似乎不起作用。我会感谢您的任何想法或建议!
In many actions from the MVC application we are building up, we use OutputCache as follows:
[OutputCache(Duration = 3600, VaryByCustom = "language")]
public ActionResult SomeAction()
{
//Action..
}
So, I want to have an action where I can flush manually all these caches:
public ActionResult RefrescarCache()
{
var keys = HttpContext.Cache.Cast<DictionaryEntry>().ToList();
keys.ForEach(k => HttpContext.Cache.Remove(k.Key.ToString()));
ViewBag.operationResult= "The cache was flushed succesfully!";
return View();
}
The thing, that it seems to not work. I will aprecciate any idea or advice you have!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们遇到了同样的问题,唯一有效的解决方案是使用:
HttpResponse.RemoveOutputCacheItem(url)
,就像 Giedrius 已经提到的那样。
We've had the same problem and the only solution which was working was with:
HttpResponse.RemoveOutputCacheItem(url)
like Giedrius already mentioned.
您应该查看此处:http://msdn.microsoft。 com/en-us/library/system.web.httpresponse.removeoutputcacheitem.aspx
You should look here: http://msdn.microsoft.com/en-us/library/system.web.httpresponse.removeoutputcacheitem.aspx
既然每个人都在寻求一种方法来清除所有的 url,
我可以想到两种方法:
1- 痛苦但简单,维护一组干净的虚拟路径。
2-使用反射来获取所有内容,示例如下:
列出 OutputCache 条目
我认为这很困难,因为它不是 ASP.NET 缓存页面,而是 IIS (7+) 内核缓存。
Since everyone is asking for a way to clear the all the url´s...
I can think of two ways:
1- painfull but easy, maintain an array of virtual paths to be clean.
2- Uses reflection to get everything, example here:
list OutputCache entry
I think this is dificult because it´s not ASP.NET caching the pages, but IIS (7+) kernel cache.