- Issue created by @slucero
- Merge request !126[#3469294] Make Pattern Entity and Asset Cache Tag Invalidation Configurable → (Merged) created by slucero
- 🇺🇸United States slucero Arkansas
After further testing, I've uncovered that the existing behavior (the currently proposed default) is not terribly helpful for several reasons:
- When patterns are used in the default layout for a content type, the cache tags present for it don't matter as much for invalidation during pattern updates since the related updates to the default layout invalidate a tag like
config:core.entity_view_display.node.page.default
which is present on every page of that content type using that display mode regardless whether it is overridden. Due to this, every page of that content type will be invalidated regardless. - When used on overridden layouts, including the invalidation of the
patternkit_pattern:<id>
cache tags will result in all pages containing this pattern being invalidated when a single instance of the pattern is updated. These other blocks won't show any changes, however, since they still point to the prior revision of the pattern entity. The same behavior is true forpattern:<asset_id>
cache tags which also get invalidated on update with this setting enabled.
Based on these findings, I'll be updating the default value for this new setting to FALSE which will represent a change in behavior for most sites already. This change should be for the better, however, by bringing cache invalidation more in line with visible changes to the content.
- When patterns are used in the default layout for a content type, the cache tags present for it don't matter as much for invalidation during pattern updates since the related updates to the default layout invalidate a tag like
- Status changed to Needs review
3 months ago 3:02pm 26 August 2024 - 🇮🇳India minsharm India
Steps to test
- Install a site locally with the following modules enabled:
- Patternkit
- Patternkit Example
- Layout Builder
- Enable cache header output →
- Configure the Basic Page content type to use layout builder with per-page overrides enabled
- Configure the default layout for Basic Page and add an instance of "[Patternkit] Example"
- Create 2 new Nodes of the Basic Page content type: Page 1, and Page 2
- Edit the layout for Page 2, override the layout saving a change to the content of the example pattern block
- As an administrator, navigate to the Patternkit settings page at
/admin/config/user-interface/patternkit
, enable the checkbox for "Entity cache tag invalidation" under "Advanced settings", and click the "Save configuration" button - In your local files, update the template file for the "[Patternkit] Example" pattern to trigger detection of a new update to the pattern being available
- Edit the file at
modules/patternkit_example/lib/patternkit/src/atoms/example/src/example.twig
in the Patternkit module directory - Add some visible markup, such as
<strong>UPDATED</strong>
, into the template so it will be clearly visible when the new template is used - Clear the Patternkit cache to discover the update:
drush pkcc
- As an administrator, edit the layout for Page 2, edit the example block, and confirm the button to "Update pattern" is available at the top of the pattern form
- Edit the file at
- As an anonymous user, view both pages confirming a successful cache response on each
- As an administrator, edit the layout for Page 2, edit the example block, click the "Update Pattern" button, and save the block. Expect to see the altered content from your template edits visible in the block preview and click "Save layout".
- As an anonymous user, view both pages expecting to see a cache miss for each
Results : Both pages show the previous content (before template changes), indicating that the cache is serving old content due to a cache hit.
- Results:
- Page 1: Shows a cache miss, displaying old content since Page 1 should not have been affected.
- Page 2: Shows the updated content and cache miss, confirming that the cache for Page 2 was correctly invalidated and updated.
- Ensure all pattern instances are up to date by running
drush pkbu
- Clear all caches with
drush cr
- As an anonymous user, view each page twice ensuring the second view returns a cache hit for each
- In your local files, update the template file for the "[Patternkit] Example" pattern to trigger detection of a new update to the pattern being available
- Edit the file at
modules/patternkit_example/lib/patternkit/src/atoms/example/src/example.twig
in the Patternkit module directory - Add some visible markup, such as
<strong>UPDATED AGAIN</strong>
, into the template so it will be clearly visible when the new template is used - Clear the Patternkit cache to discover the update:
drush pkcc
- As an administrator, edit the layout for Page 2, edit the example block, and confirm the button to "Update pattern" is available at the top of the pattern form (Do not click the button yet)
- Edit the file at
- As an anonymous user, view both pages confirming a successful cache response on each
- As an administrator, edit the layout for Page 2, edit the example block, click the "Update Pattern" button, and save the block. Expect to see the altered content from your template edits visible in the block preview and click "Save layout".
- As an anonymous user, view all both noting the page cache result
- Expect to see a cache hit on Page 1 with the content of the block showing the previous edits
- Expect to see a cache miss on Page 2 with the content of the block showing the latest edits
Results: Both pages return cache hit on second visit.
Results: Both pages return cache hit
- Results:
- Page 1: Shows the previous content (old template) with previous edits, confirming a cache hit.
- Page 2: Shows the latest content with new template changes, with cache miss
- Install a site locally with the following modules enabled:
- Status changed to RTBC
2 months ago 7:20pm 19 September 2024 - 🇺🇸United States slucero Arkansas
Merged for inclusion in the 1.0 release.
Automatically closed - issue fixed for 2 weeks with no activity.