Within this view user control, youĬould have calls to RenderPartial and RenderAction to your heart’s Now, this portion of the view will be cached, while the rest of your This allows us to move the exact code we would have Is generically typed with the same type argument that the view is, Within that control, we do what we would have done in the main viewĪnd we specify the output cache values. Suppose you have the following controller action. If that last paragraph didn’t make sense to you, perhaps an example is Generic type argument for ViewUserControl have the same type as the So if you’re using a strongly typed view, just make the Keep in mind that ViewUserControls inherit the ViewData of the view RenderAction, you’ll need to remove the OutputCache attribute from RenderPartial inside of that ViewUserControl. Simply add a ViewUserControl declaratively to a view and put your call to RenderAction or With the default WebFormViewEngine, it’s actually pretty easy to get Members of the ASP.NET team who really understand the deep grisly guts
How to get it to work for all view engines. Work for the default WebFormViewEngine, though I have some ideas on In plain English, this means that what I’m about to show you will only Rather, it appears that compilation system for ASP.NET pages kicks inĪnd interprets that directive and does the necessary gymnastics to make Matter), the output caching is not handled by the control itself. Specify the OutputCache directive on a control (or page for that I did a little digging into this today and it turns out that when you In which the entire view is cached if the target action has an Which attempts to render the output from an action inline within another
In other words, suppose you want to cache a portion of the view in aĭifferent manner (for example, with a different duration) than theĮntire view? It hasn’t been exactly clear how do to do this withįor example, the Html.RenderPartial method ignores any OutputCacheĭirectives on the view user control.
I think we should nickname all of our software concepts after tasty food To cache the donut hole, instead of the donut? However, what happens when you want to do the inverse. To cache everything but the hole in the middle. Method, but I think “Donut Caching” really describes it well - you want “cache substitution” as it makes use of the Response.WriteSubstitution The more technical term for this technique is probably A while back, I wrote about Donut Caching in ASP.NETįor the scenario where you want to cache an entire view except for a