Is there a way to have OutputCache ignore the master page in asp.net mvc?
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 r开发者_如何学运维efresh 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}
}
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.
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.
精彩评论