How to remove OutputCache on ChildAction?

扶醉桌前 提交于 2019-12-01 02:55:59

问题


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()
{
    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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/5126751/how-to-remove-outputcache-on-childaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!