Is there a way for OutputCache to ignore the main page in asp.net mvc?

I have an action that returns a main page view with a custom login item at the top. When I install outputcache, it caches all output, including the current user, so everyone will see who was the last who got on the page to update the cache as the current user. Is there a way to prevent the inclusion of the main page in the cache?

I am using the following code:

[OutputCache(Duration=3000, VaryByParam={params})] public ActionResult {actionName}({params}) { {codeGoesHere} } 
+4
source share
2 answers

The concept of " donut caching " appeared (excluding parts of the page from the output cache), but this did not work in asp.net MVC 1. To solve your problem, you can try this workaround .

+1
source

The output cache is associated with the controller, not the view. The controller may return different views based on the passed parameters. Caching can also be done using parameters (for example, in your example). When the controller caches the result, this cached value represents the generated html view (including the main page, if any). So, the short answer is: no, you cannot exclude the main page from the cache.

+1
source

All Articles