Personal wiki notebook (not under development)

Expire.py 935B

123456789101112131415161718192021222324252627282930
  1. import cherrypy
  2. def strongly_expire( function ):
  3. """
  4. Decorator that sends headers that instruct browsers and proxies not to cache.
  5. """
  6. def expire( *args, **kwargs ):
  7. cherrypy.response.headers[ "Expires" ] = "Sun, 19 Nov 1978 05:00:00 GMT"
  8. cherrypy.response.headers[ "Cache-Control" ] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
  9. cherrypy.response.headers[ "Pragma" ] = "no-cache"
  10. return function( *args, **kwargs )
  11. return expire
  12. def weakly_expire( function ):
  13. """
  14. Decorator that sends headers that instruct browsers and proxies not to cache. This cache busting
  15. isn't as strong as the @strongly_expire decorator, but it has the distinct benefit of not
  16. breaking Internet Explorer HTTPS file downloads.
  17. """
  18. def expire( *args, **kwargs ):
  19. cherrypy.response.headers[ "Expires" ] = "Sun, 19 Nov 1978 05:00:00 GMT"
  20. return function( *args, **kwargs )
  21. return expire