5

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?

tereško
  • 57,247
  • 24
  • 95
  • 149
wilk
  • 987
  • 8
  • 16
  • A couple more links: 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 Mar 26 '13 at 09:42

2 Answers2

5

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

marapet
  • 52,314
  • 12
  • 158
  • 173
ianaldo21
  • 669
  • 4
  • 10
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

Moho
  • 14,442
  • 1
  • 28
  • 30