From b18dedbe24658427799ef4909946971e6bb8e518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katja=20S=C3=BCss?= Date: Sun, 28 Oct 2018 10:41:51 +0100 Subject: [PATCH] Handling of legacy resource registries Products.ResourceRegistries removed no conditional handling --- CHANGES.rst | 2 +- docs/caching-proxies.rst | 10 +---- docs/etags.rst | 5 --- plone/app/caching/caching.zcml | 7 ---- plone/app/caching/configure.zcml | 2 - plone/app/caching/lastmodified.py | 31 ---------------- plone/app/caching/operations/configure.zcml | 1 - plone/app/caching/operations/default.py | 37 ------------------- plone/app/caching/operations/etags.py | 32 ---------------- .../registry.xml | 4 +- .../profiles/with-caching-proxy/registry.xml | 2 - .../without-caching-proxy/registry.xml | 4 +- .../tests/test_profile_with_caching_proxy.py | 12 +++--- .../test_profile_without_caching_proxy.py | 12 +++--- 14 files changed, 17 insertions(+), 144 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1dfa380..8da0012 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,7 +20,7 @@ Bug fixes: Clean-up - Legacy code clean-up -Old type resource registry Products.ResourceRegistries made optional +Handling of legacy resource registries Products.ResourceRegistries removed [ksuess] diff --git a/docs/caching-proxies.rst b/docs/caching-proxies.rst index c5fcdca..46abad8 100644 --- a/docs/caching-proxies.rst +++ b/docs/caching-proxies.rst @@ -22,12 +22,7 @@ returned to a user, because the cache has not been updated since the item was modified. There are three general strategies for dealing with this: * Since resources are cached in the proxy based on their URL, you can - "invalidate" the cached copy by changing an item's URL when it is updated. - This is the approach taken by Plone's ResourceRegistries (``portal_css``, - ``portal_javascript`` & co): in production mode, the links that are inserted - into Plone's content pages for resource managed by ResourceRegistries - contain a time-based token, which changes when the ResourceRegistries - are updated. This approach has the benefit of also being able to + "invalidate" the cached copy by changing an item's URL when it is updated. This approach has the benefit of also being able to "invalidate" content stored in a user's browser cache. * All caching proxies support setting timeouts. This means that content may @@ -90,8 +85,7 @@ The default purge paths include: ``Image`` types. Files and images created (or customised) in the ZMI are purged automatically -when modified. Files managed through the ResourceRegistries do not need -purging, since they have "stable" URLs. To purge Plone content when modified +when modified. To purge Plone content when modified (or removed), you must select the content types in the control panel. By default, only the ``File`` and ``Image`` types are purged. diff --git a/docs/etags.rst b/docs/etags.rst index 2799581..9b842c3 100644 --- a/docs/etags.rst +++ b/docs/etags.rst @@ -42,11 +42,6 @@ The ETag names tokens supported by default are: * skin The name of the current skin (theme) -* resourceRegistries - A timestamp indicating the most recent last-modified date for all three - Resource Registries. This is useful for avoiding requests for expired - resources from cached pages. - It is possible to provide additional tokens by registering an ``IETagValue`` adapter. This should be a named adapter on the published object (typically a view, file resource or Zope page template object) and request, with a unique diff --git a/plone/app/caching/caching.zcml b/plone/app/caching/caching.zcml index e81eed1..ecacf81 100644 --- a/plone/app/caching/caching.zcml +++ b/plone/app/caching/caching.zcml @@ -100,13 +100,6 @@ - - - - - - - diff --git a/plone/app/caching/configure.zcml b/plone/app/caching/configure.zcml index b5642d7..65f8623 100644 --- a/plone/app/caching/configure.zcml +++ b/plone/app/caching/configure.zcml @@ -61,7 +61,5 @@ - diff --git a/plone/app/caching/lastmodified.py b/plone/app/caching/lastmodified.py index f214e26..dd97664 100644 --- a/plone/app/caching/lastmodified.py +++ b/plone/app/caching/lastmodified.py @@ -14,13 +14,6 @@ from zope.interface import Interface from zope.pagetemplate.interfaces import IPageTemplate -# BBB resource registry of old type -try: - from Products.ResourceRegistries.interfaces import ICookedFile - from Products.ResourceRegistries.interfaces import IResourceRegistry - HAVE_RESOURCE_REGISTRIES = True -except ImportError: - HAVE_RESOURCE_REGISTRIES = False try: from zope.dublincore.interfaces import IDCTimes @@ -158,27 +151,3 @@ def __call__(self): lmt = getattr(self.context.context, 'lmt', None) if lmt is not None: return datetime.fromtimestamp(lmt, tzlocal()) - - -if HAVE_RESOURCE_REGISTRIES: - - @implementer(ILastModified) - @adapter(ICookedFile) - class CookedFileLastModified(object): - """ILastModified for Resource Registry `cooked` files - """ - - def __init__(self, context): - self.context = context - - def __call__(self): - registry = getContext(self.context, IResourceRegistry) - if ( - registry is None or - registry.getDebugMode() or - not registry.isCacheable(self.context.__name__) - ): - return None - mtime = getattr(registry.aq_base, '_p_mtime', None) - if mtime is not None and mtime > 0: - return datetime.fromtimestamp(mtime, tzlocal()) diff --git a/plone/app/caching/operations/configure.zcml b/plone/app/caching/operations/configure.zcml index 71251ab..d45a2e1 100644 --- a/plone/app/caching/operations/configure.zcml +++ b/plone/app/caching/operations/configure.zcml @@ -45,7 +45,6 @@ - diff --git a/plone/app/caching/operations/default.py b/plone/app/caching/operations/default.py index c87e117..54acab6 100644 --- a/plone/app/caching/operations/default.py +++ b/plone/app/caching/operations/default.py @@ -26,14 +26,6 @@ import time -try: - from Products.ResourceRegistries.interfaces import ICookedFile - from Products.ResourceRegistries.interfaces import IResourceRegistry - HAVE_RESOURCE_REGISTRIES = True -except ImportError: - HAVE_RESOURCE_REGISTRIES = False - - @implementer(ICachingOperation) @provider(ICachingOperationType) @adapter(Interface, Interface) @@ -299,35 +291,6 @@ class StrongCaching(BaseCaching): lastModified = ramCache = anonOnly = False -if HAVE_RESOURCE_REGISTRIES: - - @adapter(ICookedFile, IHTTPRequest) - class ResourceRegistriesCaching(StrongCaching): - """Override for StrongCaching which checks ResourceRegistries - cacheability - """ - - def interceptResponse(self, rulename, response): - return super( - ResourceRegistriesCaching, - self, - ).interceptResponse(rulename, response, class_=StrongCaching) - - def modifyResponse(self, rulename, response): - registry = getContext(self.published, IResourceRegistry) - - if registry is not None: - if ( - registry.getDebugMode() or - not registry.isCacheable(self.published.__name__) - ): - doNotCache(self.published, self.request, response) - return - - super(ResourceRegistriesCaching, self).modifyResponse( - rulename, response, class_=StrongCaching) - - @implementer(ICachingOperation) @provider(ICachingOperationType) @adapter(Interface, IHTTPRequest) diff --git a/plone/app/caching/operations/etags.py b/plone/app/caching/operations/etags.py index b7cc2a9..25934ac 100644 --- a/plone/app/caching/operations/etags.py +++ b/plone/app/caching/operations/etags.py @@ -182,38 +182,6 @@ def __call__(self): return portal_skins.getDefaultSkin() -@implementer(IETagValue) -@adapter(Interface, Interface) -class ResourceRegistries(object): - """The ``resourceRegistries`` etag component, returning the most recent - last modified timestamp from all three Resource Registries. This is - useful for avoiding requests for expired resources from cached pages. - """ - - def __init__(self, published, request): - self.published = published - self.request = request - - def __call__(self): - context = getContext(self.published) - - registries = [] - registries.append(getToolByName(context, 'portal_css', None)) - registries.append(getToolByName(context, 'portal_javascripts', None)) - registries.append(getToolByName(context, 'portal_kss', None)) - - mtimes = [] - now = time.time() - for registry in registries: - mtime = now - if registry is not None: - mtime = getattr(registry.aq_base, '_p_mtime', now) - mtimes.append(mtime) - - mtimes.sort() - return str(mtimes[-1]) - - @implementer(IETagValue) @adapter(Interface, Interface) class AnonymousOrRandom(object): diff --git a/plone/app/caching/profiles/with-caching-proxy-splitviews/registry.xml b/plone/app/caching/profiles/with-caching-proxy-splitviews/registry.xml index 22943d7..3d32eb3 100644 --- a/plone/app/caching/profiles/with-caching-proxy-splitviews/registry.xml +++ b/plone/app/caching/profiles/with-caching-proxy-splitviews/registry.xml @@ -21,7 +21,6 @@ userLanguage skin locked - resourceRegistries @@ -49,7 +48,6 @@ skin locked copy - resourceRegistries @@ -119,4 +117,4 @@ - \ No newline at end of file + diff --git a/plone/app/caching/profiles/with-caching-proxy/registry.xml b/plone/app/caching/profiles/with-caching-proxy/registry.xml index 0d30b49..56c2264 100644 --- a/plone/app/caching/profiles/with-caching-proxy/registry.xml +++ b/plone/app/caching/profiles/with-caching-proxy/registry.xml @@ -21,7 +21,6 @@ userLanguage skin locked - resourceRegistries @@ -40,7 +39,6 @@ skin locked copy - resourceRegistries diff --git a/plone/app/caching/profiles/without-caching-proxy/registry.xml b/plone/app/caching/profiles/without-caching-proxy/registry.xml index bdbe9b4..3569909 100644 --- a/plone/app/caching/profiles/without-caching-proxy/registry.xml +++ b/plone/app/caching/profiles/without-caching-proxy/registry.xml @@ -21,7 +21,6 @@ userLanguage skin locked - resourceRegistries @@ -40,7 +39,6 @@ skin locked copy - resourceRegistries @@ -94,4 +92,4 @@ - \ No newline at end of file + diff --git a/plone/app/caching/tests/test_profile_with_caching_proxy.py b/plone/app/caching/tests/test_profile_with_caching_proxy.py index b3897eb..320371d 100644 --- a/plone/app/caching/tests/test_profile_with_caching_proxy.py +++ b/plone/app/caching/tests/test_profile_with_caching_proxy.py @@ -147,7 +147,7 @@ def test_composite_viewsxx(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - self.assertEqual('"|test_user_1_|%d|en|%s|0|0' % (catalog.getCounter( + self.assertEqual('"|test_user_1_|%d|en|%s|0' % (catalog.getCounter( ), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires'])) @@ -162,7 +162,7 @@ def test_composite_viewsxx(self): browser.headers['X-Cache-Operation']) self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - self.assertEqual('"|test_user_1_|%d|en|%s|0|1' % (catalog.getCounter( + self.assertEqual('"|test_user_1_|%d|en|%s|0' % (catalog.getCounter( ), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) # Request the authenticated page @@ -181,7 +181,7 @@ def test_composite_viewsxx(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - self.assertEqual('"|test_user_1_|%d|en|%s|0' % (catalog.getCounter( + self.assertEqual('"|test_user_1_|%d|en|%s' % (catalog.getCounter( ), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires'])) @@ -227,7 +227,7 @@ def test_composite_viewsxx(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - self.assertEqual('"||%d|en|%s|0|0' % (catalog.getCounter( + self.assertEqual('"||%d|en|%s|0' % (catalog.getCounter( ), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires'])) @@ -244,7 +244,7 @@ def test_composite_viewsxx(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - self.assertEqual('"||%d|en|%s|0' % (catalog.getCounter( + self.assertEqual('"||%d|en|%s' % (catalog.getCounter( ), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires'])) @@ -264,7 +264,7 @@ def test_composite_viewsxx(self): self.assertIn(testText, browser.contents) self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - self.assertEqual('"||%d|en|%s|0' % (catalog.getCounter( + self.assertEqual('"||%d|en|%s' % (catalog.getCounter( ), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires'])) diff --git a/plone/app/caching/tests/test_profile_without_caching_proxy.py b/plone/app/caching/tests/test_profile_without_caching_proxy.py index 0692758..d19db4e 100644 --- a/plone/app/caching/tests/test_profile_without_caching_proxy.py +++ b/plone/app/caching/tests/test_profile_without_caching_proxy.py @@ -135,7 +135,7 @@ def test_composite_views(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - tag = '"|test_user_1_|{0}|en|{1}|0|0'.format( + tag = '"|test_user_1_|{0}|en|{1}|0'.format( catalog.getCounter(), default_skin, ) @@ -153,7 +153,7 @@ def test_composite_views(self): browser.headers['X-Cache-Operation']) self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - tag = '"|test_user_1_|{0}|en|{1}|0|1'.format( + tag = '"|test_user_1_|{0}|en|{1}|0'.format( catalog.getCounter(), default_skin, ) @@ -175,7 +175,7 @@ def test_composite_views(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - tag = '"|test_user_1_|{0}|en|{1}|0'.format( + tag = '"|test_user_1_|{0}|en|{1}'.format( catalog.getCounter(), default_skin, ) @@ -223,7 +223,7 @@ def test_composite_views(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - tag = '"||{0}|en|{1}|0|0'.format(catalog.getCounter(), default_skin) + tag = '"||{0}|en|{1}|0'.format(catalog.getCounter(), default_skin) self.assertEqual(tag, _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires'])) @@ -240,7 +240,7 @@ def test_composite_views(self): # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - tag = '"||{0}|en|{1}|0'.format(catalog.getCounter(), default_skin) + tag = '"||{0}|en|{1}'.format(catalog.getCounter(), default_skin) self.assertEqual(tag, _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires'])) @@ -260,7 +260,7 @@ def test_composite_views(self): self.assertIn(testText, browser.contents) self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) - tag = '"||{0}|en|{1}|0'.format(catalog.getCounter(), default_skin) + tag = '"||{0}|en|{1}'.format(catalog.getCounter(), default_skin) self.assertEqual(tag, _normalize_etag(browser.headers['ETag'])) self.assertGreater(now, dateutil.parser.parse( browser.headers['Expires']))