开发者

How to remove OutputCache on ChildAction?

开发者 https://www.devze.com 2023-02-13 19:36 出处:网络
I am trying to take advantage of the donut caching features in .Net MVC 3.For my Home page, in my home controller, I have:

I am trying to take advantage of the donut caching features in .Net MVC 3. For my Home page, in my home controller, I have:

public ActionResult Index()
{
 开发者_如何学Go   return View();
}

[ChildActionOnly]
[OutputCache(Duration=3600)]
public ActionResult IndexMain()
{
    return PartialView(ViewModelRepository.GetIndexViewModel());
}

I my view, I have:

<% Html.RenderAction("IndexMain");%>

This all works fine. However, when the data changes, I run:

var urlToRemove = Url.Action("IndexMain", "Home");
Response.RemoveOutputCacheItem(urlToRemove);

The RemoveOutputCacheItem executes without an error, but the ChildAction cache is not invalidated. Is there a way to programmatically remove a cache item from a ChildAction?


Have you tried using the VaryBy properties such as VaryByParam or VaryByCustom


There's a NuGet package to address this specific problem. This explains the problem and their solution:

http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3

0

精彩评论

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