28

By default, Tornado puts a Cache-Control: public header on any file served by a StaticFileHandler. How can this be changed to Cache-Control: no-cache?

2 Answers 2

48

The accepted answer does not work for Chrome. Subclass StaticFileHandler using the following:

class MyStaticFileHandler(tornado.web.StaticFileHandler):
    def set_extra_headers(self, path):
        # Disable cache
        self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
1
  • 1
    This worked for me on Safari and Chrome for Mac OS. +1 Commented Mar 28, 2014 at 19:49
17

Looking into the tornado/web.py it seems that the easiest way is to subclass the StaticFileHandler and override the set_extra_headers method.

def set_extra_headers(self, path):
    self.set_header("Cache-control", "no-cache")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.