开发者

Find all action methods that have been decorated with [OutputCache] and remove

开发者 https://www.devze.com 2023-03-05 00:57 出处:网络
Is it possible to find all Action methods on all controllers that have been decorated with [OutputCache] so I can then enumerate through them to remove selected items from the cache in one go?

Is it possible to find all Action methods on all controllers that have been decorated with [OutputCache] so I can then enumerate through them to remove selected items from the cache in one go?

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

According to this post it is not possible to invalidate the cache in one go.

Edit It looks like I can invalidate the ALL the cache by simply doing this:-

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

See this post for more info. However it would be nice to inval开发者_如何学Goidate portions of the cache depending say on controller name etc.


Looks like

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

has done the trick...

0

精彩评论

暂无评论...
验证码 换一张
取 消