disabling client side caching for the whole site in Django
If you have to disable client side caching in Django because of a defective proxy imposed by an ISP that caches pages it shouldn't, this middleware will come in handy:
- from django.utils.cache import add_never_cache_headers
-
- class DisableClientSideCaching(object):
- def process_response(self, request, response):
- try:
- if request.user.is_authenticated():
- add_never_cache_headers(response)
- except:
- pass
- return response
It kicks in only for logged in users. The try block is there because the automatic redirection from /foo/bar to /foo/bar/ triggers an exception in request.user.is_authenticated() - some data is not available in the request object.
Category: Django



Leave a Comment :
Leave a Comment