Skip to content

Commit

Permalink
Revert part of "Handling of legacy resource registries Products.Resou…
Browse files Browse the repository at this point in the history
…rceRegistries removed"

This partially reverts commit b18dedb.

Specifically:

- This reintroduces the resourceRegistries ETag in the various caching profiles.
- Adds documentation for the ETag.
- Adapts the tests to expect content for the ETag.

The tests will need changes though.

The legacy resource registries (portal_css/kss/javascript) are definitely not supported with this revert.
This is only about the "new-style" Plone 5 resource registries in `@@resourceregistry-controlpanel`.
  • Loading branch information
mauritsvanrees committed Jan 25, 2021
1 parent 5e799b3 commit b9a37a2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
11 changes: 9 additions & 2 deletions docs/caching-proxies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ 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 approach has the benefit of also being able to
"invalidate" the cached copy by changing an item's URL when it is updated.
This is the approach taken by Plone's ResourceRegistries:
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, more specifically: when the resource bundles are combined.
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
Expand Down Expand Up @@ -85,7 +91,8 @@ The default purge paths include:
``Image`` types.

Files and images created (or customised) in the ZMI are purged automatically
when modified. To purge Plone content when modified
when modified. Files managed through the ResourceRegistries do not need
purging, since they have "stable" URLs. 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.

Expand Down
5 changes: 5 additions & 0 deletions docs/etags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ The ETag names tokens supported by default are:
* skin
The name of the current skin (theme)

* resourceRegistries
A timestamp indicating the last-modified timestamp for the
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<element>userLanguage</element>
<element>skin</element>
<element>locked</element>
<element>resourceRegistries</element>
</value>
</record>
<record name="plone.app.caching.moderateCaching.plone.content.itemView.ramCache">
Expand Down Expand Up @@ -48,6 +49,7 @@
<element>skin</element>
<element>locked</element>
<element>copy</element>
<element>resourceRegistries</element>
</value>
</record>
<record name="plone.app.caching.moderateCaching.plone.content.folderView.ramCache">
Expand Down Expand Up @@ -117,4 +119,4 @@
</record>


</registry>
</registry>
2 changes: 2 additions & 0 deletions plone/app/caching/profiles/with-caching-proxy/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<element>userLanguage</element>
<element>skin</element>
<element>locked</element>
<element>resourceRegistries</element>
</value>
</record>
<record name="plone.app.caching.weakCaching.plone.content.itemView.ramCache">
Expand All @@ -39,6 +40,7 @@
<element>skin</element>
<element>locked</element>
<element>copy</element>
<element>resourceRegistries</element>
</value>
</record>
<record name="plone.app.caching.weakCaching.plone.content.folderView.ramCache">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<element>userLanguage</element>
<element>skin</element>
<element>locked</element>
<element>resourceRegistries</element>
</value>
</record>
<record name="plone.app.caching.weakCaching.plone.content.itemView.ramCache">
Expand All @@ -39,6 +40,7 @@
<element>skin</element>
<element>locked</element>
<element>copy</element>
<element>resourceRegistries</element>
</value>
</record>
<record name="plone.app.caching.weakCaching.plone.content.folderView.ramCache">
Expand Down Expand Up @@ -92,4 +94,4 @@
</record>


</registry>
</registry>
12 changes: 6 additions & 6 deletions plone/app/caching/tests/test_profile_with_caching_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' % (catalog.getCounter(
self.assertEqual('"|test_user_1_|%d|en|%s|0|0' % (catalog.getCounter(
), skins_tool.default_skin), _normalize_etag(browser.headers['ETag']))
self.assertGreater(now, dateutil.parser.parse(
browser.headers['Expires']))
Expand All @@ -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' % (catalog.getCounter(
self.assertEqual('"|test_user_1_|%d|en|%s|0|1' % (catalog.getCounter(
), skins_tool.default_skin), _normalize_etag(browser.headers['ETag']))

# Request the authenticated page
Expand All @@ -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' % (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']))
Expand Down Expand Up @@ -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' % (catalog.getCounter(
self.assertEqual('"||%d|en|%s|0|0' % (catalog.getCounter(
), skins_tool.default_skin), _normalize_etag(browser.headers['ETag']))
self.assertGreater(now, dateutil.parser.parse(
browser.headers['Expires']))
Expand All @@ -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' % (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']))
Expand All @@ -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' % (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']))
Expand Down
12 changes: 6 additions & 6 deletions plone/app/caching/tests/test_profile_without_caching_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'.format(
tag = '"|test_user_1_|{0}|en|{1}|0|0'.format(
catalog.getCounter(),
default_skin,
)
Expand All @@ -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'.format(
tag = '"|test_user_1_|{0}|en|{1}|0|1'.format(
catalog.getCounter(),
default_skin,
)
Expand All @@ -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}'.format(
tag = '"|test_user_1_|{0}|en|{1}|0'.format(
catalog.getCounter(),
default_skin,
)
Expand Down Expand Up @@ -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'.format(catalog.getCounter(), default_skin)
tag = '"||{0}|en|{1}|0|0'.format(catalog.getCounter(), default_skin)
self.assertEqual(tag, _normalize_etag(browser.headers['ETag']))
self.assertGreater(now, dateutil.parser.parse(
browser.headers['Expires']))
Expand All @@ -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}'.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']))
Expand All @@ -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}'.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']))
Expand Down

0 comments on commit b9a37a2

Please sign in to comment.