I've set up page level caching for many of our pages. However once in a while an admin user logs in to preview potential changes to the site.
Is there a way to disable page level caching just for these users?
I read through the docs but I didn't see anything.
Update: Here's my attempt based on v1k45's answer:
from django.middleware.cache import FetchFromCacheMiddleware
logger = logging.getLogger(__name__)
class ExceptImpersonateFetchFromCacheMiddleware(FetchFromCacheMiddleware):
def process_request(self, request):
# Break out of caching is we're using impersonate
if request.user and hasattr(request.user, 'is_impersonate') and request.user.is_impersonate:
logger.warning("Skipping cache_page for user %s because it is impersonation" % str(request.user))
request._cache_update_cache = False
return None
# Normal flow:
return super(ExceptImpersonateFetchFromCacheMiddleware, self).process_request(request)