I'd like to cache the output of my MVC actions. However:
1) If I apply the OutputCacheAttribute
globally, it is risky as it caches everything for all users.
2) If I apply OutputCacheAttribute
globally and then apply the Authorize
attribute on those actions that require authorization, that still does not solve the problem. All output is still cached regardless of the user having been authorized or not.
3) If I apply the OutputCacheAttribute
(not globally but) only on select actions, and have the AuthorizeAttribute
on all actions that require authorization, then there is no security threat but there is a performance cost. Every page that requires authentication will need to make a fresh Http request.
I want to find a middle-ground so that selected pages, and/or selected types of requests (HTTP GET) are cached at the client but only if the user is authenticated. If the user logs out and accesses the url of the cached page/action, he must not be able to see the content.
Is there a way to implement this?