Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 548
Kennet Belenky Avatar asked Oct 13 '10 18:10

Kennet Belenky


1 Answers

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

like image 167
Restuta Avatar answered Oct 03 '22 19:10

Restuta