3

In my MVC3 Project I use some output caching with the OutputCache attribute set on the action. However there are certain sections on this page that I dont want to cache ever.

Is it possible to have some partials in my view that overrides the pages caching?

dkarzon
  • 7,868
  • 9
  • 48
  • 61
  • 1
    Were you ever able to get a solution for this? It seems that the link below goes does the opposite (caches the partial but not the page, while you seem to want to cache the page but not the partial). – longda Sep 03 '11 at 01:01

4 Answers4

5

You can now get proper donut caching by downloading the MvcDonutCaching NuGet package. See http://mvcdonutcaching.codeplex.com/ and http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3 for more information.

Paul Hiles
  • 9,558
  • 7
  • 51
  • 76
  • Do you know if there is any way to work with MVC DonutCaching and SqlDependency? In my action `Index` use the `DonutOutputCache`. I have an action `ProjectList` that generates a list of projects. How can I use `SqlDependency` in `ProjectList (partial)` action? – ridermansb Dec 27 '11 at 18:51
0

Yes you are 'supposed' to be able to do this. See: Partial Views Caching in ASP.NET MVC 3

Also I use a method to disable caching for controllers here:

Disable browser cache for entire ASP.NET website

Community
  • 1
  • 1
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • Hmmm, didnt seem to work properly getting this error: "OutputCacheAttribute for child actions only supports Duration, VaryByCustom, and VaryByParam values. Please do not set CacheProfile, Location, NoStore, SqlDependency, VaryByContentEncoding, or VaryByHeader values for child actions." – dkarzon Jun 17 '11 at 23:55
  • What values did you set on the child action? – Adam Tuliper Jun 18 '11 at 03:32
  • [OutputCache(NoStore = true, Duration = 60, VaryByParam = "*")] and the page itself had [OutputCache(Duration = 36000, VaryByParam = "id")] – dkarzon Jun 19 '11 at 22:41
0

Seems like this is the answer: http://weblogs.asp.net/scottgu/archive/2006/11/28/tip-trick-implement-donut-caching-with-the-asp-net-2-0-output-cache-substitution-feature.aspx

You basically have two options:

  1. Refactor the page so that rather than caching the entire page, you identify all the specific pieces (controls, partials, etc) that should be cached. (boo)
  2. Use output substitution blocks as Scott Guthrie describes in the link. (boo as well unless the replacement is just simple text)
longda
  • 10,153
  • 7
  • 46
  • 66
0

This is called donut caching and isn't supported out of the box in MVC3. Check out my similar question here. Specifically, Jan Jongboom's Moth library which he suggests can do this (though I cannot confirm or deny this)

Community
  • 1
  • 1
JP.
  • 5,536
  • 7
  • 58
  • 100