简体   繁体   English

在Tornado中禁用静态文件缓存

[英]Disable static file caching in Tornado

By default, Tornado puts a Cache-Control: public header on any file served by a StaticFileHandler . 默认情况下,Tornado在StaticFileHandler提供的任何文件上放置一个Cache-Control: public头。 How can this be changed to Cache-Control: no-cache ? 如何将其更改为Cache-Control: no-cache

The accepted answer does not work for Chrome. 接受的答案不适用于Chrome。 Subclass StaticFileHandler using the following: 子类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')

Looking into the tornado/web.py it seems that the easiest way is to subclass the StaticFileHandler and override the set_extra_headers method. 查看tornado / web.py似乎最简单的方法是子类化StaticFileHandler并覆盖set_extra_headers方法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM