From 2db54531f2279369846ddf96a83b1417b8852146 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 19 Dec 2016 18:22:40 -0500 Subject: [PATCH] Extend caching for versioned assets. --- calefaction/util.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/calefaction/util.py b/calefaction/util.py index 770a7a1..65dac67 100644 --- a/calefaction/util.py +++ b/calefaction/util.py @@ -5,7 +5,7 @@ from hashlib import md5 from os import path from traceback import format_exc -from flask import flash, url_for +from flask import flash, request, url_for from flask_mako import render_template, TemplateError from .exceptions import AccessDeniedError, EVEAPIError @@ -81,5 +81,13 @@ def set_up_asset_versioning(app): return url_for("static", filename=filename, v=hashstr) raise error + old_get_max_age = app.get_send_file_max_age + + def extend_max_age(filename): + if "v" in request.args: + return 60 * 60 * 24 * 365 # 1 year + return old_get_max_age(filename) + app._hash_cache = {} app.url_build_error_handlers.append(lambda a, b, c: callback(app, a, b, c)) + app.get_send_file_max_age = extend_max_age