【问题标题】:How to remove OutputCache on ChildAction?如何删除 ChildAction 上的 OutputCache?
【发布时间】:2011-02-26 12:00:16
【问题描述】:

我正在尝试利用 .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 中删除缓存项?

【问题讨论】:

标签: asp.net-mvc asp.net-mvc-3 outputcache


【解决方案1】:

您是否尝试过使用 VaryBy 属性,例如 VaryByParam or VaryByCustom

【讨论】:

  • 看起来这是不使用全面重新实现的唯一方法。
【解决方案2】:

有一个 NuGet 包可以解决这个特定问题。这解释了问题及其解决方案:

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

【讨论】:

    猜你喜欢
    • 2016-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多