找到已使用[OutputCache]修饰的所有操作方法并删除

时间:2011-05-10 12:01:18

标签: c# caching asp.net-mvc-3

是否可以在所有使用[OutputCache]修饰的控制器上找到所有Action方法,以便我可以通过它们枚举来一次性从缓存中删除selected个项目?

foreach(var .. in ...)
{
  //get ActionName
  //get ControllerName
  HttpResponse.RemoveOutputCacheItem(Url.Action(ActionName, ControllerName));
}

根据此post,无法一次性使缓存失效。

修改看起来我只需执行此操作即可使ALL缓存无效: -

public ActionResult Invalidate()
{
    OutputCacheAttribute.ChildActionCache = new MemoryCache("NewDefault");
    return View();
}

有关详细信息,请参阅此post。然而,取决于控制器名称等,使高速缓存的部分无效将是很好的。

1 个答案:

答案 0 :(得分:1)

看起来像

public ActionResult Invalidate()
{
    OutputCacheAttribute.ChildActionCache = new MemoryCache("NewDefault");
    return View();
}

已经成功了......