What's the current practice for partial caching in ASP MVC2?
Asked Answered
H

1

8

My website pages are composed of two kinds of content. The first is variable between users but constant for all pages. The second is constant across users, but variable between pages. This is a common layout. What is the best way to apply output caching to content like this?

As I understand it, the Html.Substitute helper is incompatible with the MVC2 rendering pipeline, eliminating the old way of donut caching.

Use normal output caching with VaryByParam="user" for every page?

The level of specificity would reduce the value of output caching. It's unlikely that the same user will view the same page very many times within the lifespan of the cached output.

Use a alternate OutputCache subsystem

There are several attempts floating around the internet that modify the OutputCache attribute and rendering subsystem to support substitution. The best one I've found is here.

However, the various snippets I've found seem to be informal implementations, and aren't well supported. Additionally, I'm inclined to suspect that if it were that easy to add substitution back into the MVC2 pipeline, it would've been done.

Compose the final page from several child actions which are individually cached

The action method would not be flagged with an OutputCache attribute, and would return a view which contains several Html.RenderAction invocations which would pull in independently cached content. Aside from the slightly heavyweight implications of using RenderAction, it would add an extra layer of indirection and a code smell.

What is your experience with composing independently cached content in MVC2? What's worked well and what hasn't?

Harberd answered 13/10, 2010 at 18:9 Comment(1)
I would wait for the MVC3 (It is already in RC with go-live license), and try to use data caching as much as possible in the mean time. Basically any other solution you will spend time implementing now will be trashed within the next few months.Periclean
F
1

Please take a look at this question ans also info how stackoverflow does this can help you.

Fieldpiece answered 11/1, 2011 at 22:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.