在Tornado中禁用静态文件缓存

28

默认情况下,Tornado会在通过StaticFileHandler提供的任何文件上放置一个Cache-Control: public标头。如何将其更改为Cache-Control: no-cache

2个回答

48

被接受的答案在Chrome中不起作用。请使用以下方式对StaticFileHandler进行子类化:

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
这对我在Mac OS上的Safari和Chrome可行。+1 - Randall Cook

17

通过查阅tornado/web.py的文档,似乎最简单的方法是继承StaticFileHandler并重写set_extra_headers方法。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接