Home » Odeon Blogs » Stefan Talpalaru, CTO »

disabling client side caching for the whole site in Django

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:

  1. from django.utils.cache import add_never_cache_headers
  2. class DisableClientSideCaching(object):
  3. def process_response(self, request, response):
  4. try:
  5. if request.user.is_authenticated():
  6. add_never_cache_headers(response)
  7. except:
  8. pass
  9. 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 :

(required)


(required)




(required)




(required)






Leave a Comment


Page generated in: 0.15s