views:

165

answers:

3

I have an action that returns a view with a master page with a logon user control at the top. When I set outputcache, it caches the entire output including the current user, so everybody would see whoever was the last person to hit the page to refresh the cache as the current user. Is there a way to prevent the master page from being included in the cache?

I am using the following code:

[OutputCache(Duration=3000, VaryByParam={params})]  
public ActionResult {actionName}({params})  
{  
    {codeGoesHere}  
}
+1  A: 

Take a look at this link : Partial Output Caching in ASP.NET MVC Hope this helps.

ali62b
Thanks for the article!
mynameiscoffey
+1  A: 

Output cache is associated with the controller, not the view. A controller may return different views, based on the passed parameters. Caching may also be done by parameters (like you have in your example). When the result of a controller is cached, that cached value is the view's generated html (including the master page if any). So, the short answer is, no, you can't exclude the master page from the cache.

Ralph Stevens
+1  A: 

There was a concept of "donut caching" (excluding parts of a page from the output cache) but it didn't made it in asp.net MVC 1. For solution to your problem you can try this workaround.

Branislav Abadjimarinov