【问题标题】:OutputCache Flush Cache through an Action in an MVC 3 ApplicationOutputCache 通过 MVC 3 应用程序中的操作刷新缓存
【发布时间】:2011-11-18 16:16:40
【问题描述】:

在我们正在构建的 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();
        }

事情,它似乎不起作用。我会感谢您的任何想法或建议!

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-3 c#-4.0 action outputcache


    【解决方案1】:

    我们遇到了同样的问题,唯一有效的解决方案是:

    HttpResponse.RemoveOutputCacheItem(url)

    就像 Giedrius 已经提到的那样。

    【讨论】:

    • 有没有办法为所有的网址做这件事?
    • 缓存的 url 是否保存在某个数组/对象中?
    • 猜我们永远不会知道
    【解决方案2】:

    【讨论】:

    • 似乎只针对一个网址,有什么办法可以做到吗?
    • 我用这个把头发扯掉了... RemoveOutputCacheItem 非常简单
    • 我想我们永远不会知道
    【解决方案3】:

    由于每个人都在寻求一种清除所有网址的方法...

    我可以想到两种方法:

    1- 痛苦但容易,保持一系列虚拟路径是干净的。

    foreach(string path in myArray){HttpResponse.RemoveOutputCacheItem(path); }
    

    2- 使用反射来获取所有内容,示例如下: list OutputCache entry

    我认为这很困难,因为它不是 ASP.NET 缓存页面,而是 IIS (7+) 内核缓存。

    【讨论】:

      猜你喜欢
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      • 2015-05-05
      • 2013-11-26
      相关资源
      最近更新 更多