[IMP] http, *: review cache TTL values
* base, web Google now recommends a TTL of one year for static contents. We used to use 1 week in almost every case. This commit increases that value to one year for safe resources, like assets bundles which contain a specific hash in the URL which changes if the bundle is recomputed anyway. Note: this commit refactors the code so that both the one week and one year durations are defined in http.py and used by others apps. Loading the library "locale" file used to be done with 10-hours-cache, this has been increased to 1-week-cache by using the http.py STATIC_CACHE var. closes odoo/odoo#37402 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -59,11 +59,7 @@ else:
|
||||
env = jinja2.Environment(loader=loader, autoescape=True)
|
||||
env.filters["json"] = json.dumps
|
||||
|
||||
# 1 week cache for asset bundles as advised by Google Page Speed
|
||||
BUNDLE_MAXAGE = 60 * 60 * 24 * 7
|
||||
|
||||
# 1 year cache for content (menus, translations, static qweb)
|
||||
CONTENT_MAXAGE = 60 * 60 * 24 * 356
|
||||
CONTENT_MAXAGE = http.STATIC_CACHE_LONG # menus, translations, static qweb
|
||||
|
||||
DBNAME_PATTERN = '^[a-zA-Z0-9][a-zA-Z0-9_.-]+$'
|
||||
|
||||
@@ -889,7 +885,7 @@ class WebClient(http.Controller):
|
||||
file_open('web/static/lib/moment/locale/%s.js' % code, 'rb')
|
||||
),
|
||||
content_type='application/javascript; charset=utf-8',
|
||||
headers=[('Cache-Control', 'max-age=36000')],
|
||||
headers=[('Cache-Control', 'max-age=%s' % http.STATIC_CACHE)],
|
||||
direct_passthrough=True,
|
||||
)
|
||||
except IOError:
|
||||
@@ -897,7 +893,7 @@ class WebClient(http.Controller):
|
||||
|
||||
return request.make_response("", headers=[
|
||||
('Content-Type', 'application/javascript'),
|
||||
('Cache-Control', 'max-age=36000'),
|
||||
('Cache-Control', 'max-age=%s' % http.STATIC_CACHE),
|
||||
])
|
||||
|
||||
@http.route('/web/webclient/qweb/<string:unique>', type='http', auth="none", cors="*")
|
||||
|
||||
@@ -20,7 +20,7 @@ import werkzeug.utils
|
||||
import odoo
|
||||
from odoo import api, http, models, tools, SUPERUSER_ID
|
||||
from odoo.exceptions import AccessDenied, AccessError
|
||||
from odoo.http import request, STATIC_CACHE, content_disposition
|
||||
from odoo.http import request, content_disposition
|
||||
from odoo.tools import consteq, pycompat
|
||||
from odoo.tools.mimetypes import guess_mimetype
|
||||
from odoo.modules.module import get_resource_path, get_module_path
|
||||
@@ -393,7 +393,7 @@ class IrHttp(models.AbstractModel):
|
||||
headers.append(('ETag', filehash))
|
||||
if etag == filehash and status == 200:
|
||||
status = 304
|
||||
headers.append(('Cache-Control', 'max-age=%s' % (STATIC_CACHE if unique else 0)))
|
||||
headers.append(('Cache-Control', 'max-age=%s' % (http.STATIC_CACHE_LONG if unique else 0)))
|
||||
# content-disposition default name
|
||||
if download:
|
||||
headers.append(('Content-Disposition', content_disposition(filename)))
|
||||
|
||||
+5
-2
@@ -58,8 +58,11 @@ _logger = logging.getLogger(__name__)
|
||||
rpc_request = logging.getLogger(__name__ + '.rpc.request')
|
||||
rpc_response = logging.getLogger(__name__ + '.rpc.response')
|
||||
|
||||
# 1 week cache for statics as advised by Google Page Speed
|
||||
STATIC_CACHE = 60 * 60 * 24 * 7
|
||||
# One week cache for static content (static files in apps, library files, ...)
|
||||
# Safe resources may use what google page speed recommends (1 year)
|
||||
# (attachments with unique hash in the URL, ...)
|
||||
STATIC_CACHE = 3600 * 24 * 7
|
||||
STATIC_CACHE_LONG = 3600 * 24 * 365
|
||||
|
||||
# To remove when corrected in Babel
|
||||
babel.core.LOCALE_ALIASES['nb'] = 'nb_NO'
|
||||
|
||||
Reference in New Issue
Block a user