Fix static assets cache logic (#5700)

This commit is contained in:
J. Nick Koston 2023-11-08 15:04:01 -06:00 committed by GitHub
parent 511348974e
commit cf22c55430
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ import base64
import binascii import binascii
import codecs import codecs
import collections import collections
import datetime
import functools import functools
import gzip import gzip
import hashlib import hashlib
@ -1406,15 +1407,17 @@ def make_app(debug=get_bool_env(ENV_DEV)):
) )
class StaticFileHandler(tornado.web.StaticFileHandler): class StaticFileHandler(tornado.web.StaticFileHandler):
def set_extra_headers(self, path): def get_cache_time(
if "favicon.ico" in path: self, path: str, modified: datetime.datetime | None, mime_type: str
self.set_header("Cache-Control", "max-age=84600, public") ) -> int:
else: """Override to customize cache control behavior."""
if debug: if debug:
self.set_header( return 0
"Cache-Control", # Assets that are hashed have ?hash= in the URL, all javascript
"no-store, no-cache, must-revalidate, max-age=0", # filenames hashed so we can cache them for a long time
) if "hash" in self.request.arguments or "/javascript" in mime_type:
return self.CACHE_MAX_AGE
return super().get_cache_time(path, modified, mime_type)
app_settings = { app_settings = {
"debug": debug, "debug": debug,