Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC 2 caching

I'm currently developing a web site using asp.net mvc 2 in c#. I have never used the caching feature in MVC and would like to apply it to the user profile page. The content on this page rarely changes and the only part that needs to be in realtime is the list of recent posts by the user. (I use linq-to-sql to load data from the database)

I need some suggestions on what caching technique I should use and how to implement it?

Update: Xandy's solution below almost works, except I cannot pass in data. How would I rewrite this using the ? Html.RenderPartial("UserPosts", ViewData["UserPosts"])

like image 443
Rana Avatar asked Nov 04 '10 00:11

Rana


1 Answers

Phil Hack's fragment caching tricks no longer work in MVC2.

At StackOverflow we build html fragments as text and cache them using HttpRuntime.Cache and more.

like image 178
Sam Saffron Avatar answered Oct 18 '22 03:10

Sam Saffron