Disable static file caching in Tornado

Jordan picture Jordan · Aug 20, 2012 · Viewed 9.4k times · Source

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?

Answer

0xdabbad00 picture 0xdabbad00 · Sep 18, 2013

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')