如何在ChildAction删除的OutputCache? [英] How to remove OutputCache on ChildAction?

查看:164
本文介绍了如何在ChildAction删除的OutputCache?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想利用在.net MVC 3甜甜圈缓存功能对于我的主页,在我家的控制器,我有:

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);

该RemoveOutputCacheItem执行没有错误,但ChildAction缓存不会失效。有没有一种方法以编程方式从ChildAction删除缓存项?

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?

推荐答案

您是否尝试过使用VaryBy性能如的的VaryByParam或VaryByCustom是

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

这篇关于如何在ChildAction删除的OutputCache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆