2011-02-26 19 views
5

我想利用在.net MVC 3甜甜圈缓存功能对于我的主页,在我家的控制器,我有:如何删除ChildAction上的OutputCache?

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

一对夫妇更多的联系:http://stackoverflow.com/a/7530265/63733,http://thenullreference.com/blog/fixing-the-asp -net-mvc-3-outputcacheattribute-for-partial-views-to-honor-some-web-config-settings /,http://stackoverflow.com/a/7117242/63733 – marapet 2013-03-26 09:42:18

回答

5

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

+1

看起来像这是唯一的方法没有使用完整的重新实现。 – marapet 2013-03-26 14:52:40

+0

赏金答复这个答案 - 让我们不要浪费声望点... – marapet 2013-04-01 20:40:30