tags:

views:

302

answers:

3

Currently ASP.NET MVC's OutputCache attribute has a huge downfall. If you want to cache parts of your site you have to use a workaround due to the limitation of ASP.NET's pipeline that MVC relies on.

Say you have a page that has a statistics module that you surface through RenderAction you can't cache just that part of the page out of the box.

My question is, what ways have you found to get around this limitation that are elegant and easy to use? I've personally found 2 of them neither I'm particularly happy with. Though they work they seem to just feel wrong when building an app around them.

Solution 1 - Sub Controllers http://mhinze.com/subcontrollers-in-aspnet-mvc/

Solution 2 - Partial requests http://blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc/

So if you have another solution or maybe even a way you've used one of these solutions elegantly I'd love some ideas on design and/or usage.

A: 

How about using jQuery to load some of the areas (divs etc) via ajax. Then you can cache different areas as complete requests, with different granularity.

Marc Gravell
I was thinking about that but I'd hate to not have downlevel support for those that have javascript disabled.
Chad Moran
+4  A: 

I've done this with option 2 (using Html.RenderAction) with pretty good success. I also created different base classes for my controllers, one that caches and one that doesn't so that I put all of my cached actions in one place. I don't do this very often so it's not too bad to isolate these actions. With a combination of caching and a GZip compression filter I wrote I get pretty blazing performance out of MVC.

EDIT: I just finished a blog post on adding simple compression to ASP.NET MVC at http://www.thegrubbsian.com/?p=202

JC Grubbs
+4  A: 

In some cases it's better not to use ASP.NET OutputCache feature at all. Instead use Caching in your business/service layer with optional gzip compression. Sometimes this combination is even faster than full output caching.

eu-ge-ne
Can you explain what you mean by 'caching in the service layer'? Do you mean return compressed results from your service layer?
cottsak
I mean caching of your data (ASP.NET Cache, NVelocity, Memcached or any) and/or response compressing
eu-ge-ne