我正在尝试利用.Net MVC 3中的甜甜圈缓存功能。对于我的主页,在我的家庭控制器中,我有:
public ActionResult Index()
{
return View();
}
[ChildActionOnly]
[OutputCache(Duration=3600)]
public ActionResult IndexMain()
{
return PartialView(ViewModelRepository.GetIndexViewModel());
}
我的观点,我有:
<% Html.RenderAction("IndexMain");%>
一切正常。但是,当数据发生变化时,我运行:
var urlToRemove = Url.Action("IndexMain", "Home");
Response.RemoveOutputCacheItem(urlToRemove);
RemoveOutputCacheItem执行时没有错误,但ChildAction缓存未失效。有没有办法以编程方式从ChildAction中删除缓存项?
答案 0 :(得分:5)
您是否尝试过使用VaryBy属性,例如VaryByParam or VaryByCustom
答案 1 :(得分:2)
有一个NuGet包来解决这个特定问题。这解释了问题及其解决方案:
http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3