From 85ef73dcb975882f6c9a35fbc54f0c115e6c6a33 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 11 Feb 2022 16:55:25 -0600 Subject: [PATCH] Tell browser not to cache certain pages, by default main grid/index pages, and any view page which contains a row grid --- tailbone/views/master.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index bcbb58d3..77a844a4 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -4485,21 +4485,22 @@ class MasterView(View): config.add_tailbone_permission_group(permission_prefix, model_title_plural, overwrite=False) + # on windows/chrome we are seeing some caching when e.g. user + # applies some filters, then views a record, then clicks back + # button, filters no longer are applied. so by default we + # instruct browser to never cache certain pages which contain + # a grid. at this point only /index and /view + # cf. https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/viewconfig.html#non-predicate-arguments + prevent_cache = rattail_config.getbool('tailbone', + 'prevent_cache_for_index_views', + default=True) + # list/search if cls.listable: config.add_tailbone_permission(permission_prefix, '{}.list'.format(permission_prefix), "List / search {}".format(model_title_plural)) config.add_route(route_prefix, '{}/'.format(url_prefix)) - kwargs = {} - if rattail_config.getbool('tailbone', - 'prevent_cache_for_index_views', - default=False): - # hopefully, instruct browser to never cache this page. - # on windows/chrome we are seeing some caching when e.g. - # user applies some filters, then views a record, then - # clicks back button, filters no longer are applied - # cf. https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/viewconfig.html#non-predicate-arguments - kwargs['http_cache'] = 0 + kwargs = {'http_cache': 0} if prevent_cache else {} config.add_view(cls, attr='index', route_name=route_prefix, permission='{}.list'.format(permission_prefix), **kwargs) @@ -4667,8 +4668,10 @@ class MasterView(View): # view by record key config.add_route('{}.view'.format(route_prefix), instance_url_prefix) + kwargs = {'http_cache': 0} if prevent_cache and cls.has_rows else {} config.add_view(cls, attr='view', route_name='{}.view'.format(route_prefix), - permission='{}.view'.format(permission_prefix)) + permission='{}.view'.format(permission_prefix), + **kwargs) # version history if cls.has_versions and rattail_config and rattail_config.versioning_enabled():