Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways to workaround whole page caching in ASP.NET MVC

Tags:

c#

asp.net-mvc

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.

like image 692
Chad Moran Avatar asked Jan 23 '23 15:01

Chad Moran


1 Answers

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.

like image 139
JC Grubbs Avatar answered Feb 07 '23 04:02

JC Grubbs