MVC3 RenderPartial Multi-Page Caching

Can someone tell me if it is possible to cache it with RenderPartial on multiple pages? I have a RenderPartial for a user profile that should never change unless the user updates his profile. So I really do not want to come back and get his / her profile every time I load the page. I would rather pass a partial round until they had to update (i.e. update the profile)

I looked at the DonutHole example that p.hack put together, but it seems to be suitable for a single page. Can someone point me in the right direction or offer any advice? Or can I only cache one page at a time? thanks!

+7
source share
1 answer

You can use RenderAction instead. Example:

public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult About() { return View(); } [OutputCache(Duration = 6000, VaryByParam = "none")] public ActionResult Cached() { // You could return whatever you want here, even a view // but for the purpose of the demonstration I am simply // returning a dynamic string value return Content(DateTime.Now.ToLongTimeString(), "text/html"); } } 

and inside the Index.cshtml and About.cshtml you can include a child action:

 <div> @{Html.RenderAction("Cached");} </div> 

and you will get its cached version on both pages.

+11
source

All Articles