【发布时间】:2012-08-15 09:22:24
【问题描述】:
默认情况下,Tornado 会将Cache-Control: public 标头放在StaticFileHandler 提供的任何文件上。这个怎么改成Cache-Control: no-cache?
【问题讨论】:
标签: python caching tornado static-files
默认情况下,Tornado 会将Cache-Control: public 标头放在StaticFileHandler 提供的任何文件上。这个怎么改成Cache-Control: no-cache?
【问题讨论】:
标签: python caching tornado static-files
查看 tornado/web.py 似乎最简单的方法是继承 StaticFileHandler 并覆盖 set_extra_headers 方法。
def set_extra_headers(self, path):
self.set_header("Cache-control", "no-cache")
【讨论】:
接受的答案不适用于 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')
【讨论】: