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
?
默认情况下,Tornado在StaticFileHandler提供的任何文件上放置一个Cache-Control:public头。如何将其更改为Cache-Control:no-cache?
2 个解决方案
#1
13
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")
#2
41
The accepted answer does not work for Chrome. Subclass StaticFileHandler
using the following:
接受的答案不适用于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
13
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")
#2
41
The accepted answer does not work for Chrome. Subclass StaticFileHandler
using the following:
接受的答案不适用于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')