Cache tags for referenced entities
Background
Recently another MR was created by @martijn which adds cache tags to the /translate-path
endpoint for referenced content (e.g. Media).
That makes sure that when you change that media, the cache for the page that it's referenced on is also invalidated.
Problem
This solution works good, but has two problems:
- It doesn't work for referenced Paragraphs
- It doesn't add those cache tags to the HTML page cache, only to the
/translate-path
API cache. This raises issues when you have implemented our SSR setup, where the content of the page is stored in the HTML (thus in the cache), instead of being fetched at request time.
Solution
To accommodate for these issues the following changes have been made:
- We now also check for fields of type
entity_reference_revisions
(usually the type used for Paragraphs), instead of only checking for fields of typeentity_reference
(usually the type used for Media) - We now execute this same cache tag logic in the
hook_page_attachements_alter
, effectively adding the same cache tags to the HTML page cache also.
To prevent code duplication whilst solving problem 2 the cache tag logic has been placed in a reusable service.
Next steps
This setup still has one problem, that is:
- Entities that are not referenced in the page entity, but are SSR'ed (mostly Menus, but also Blocks), won't be added to the cache tags of the page entity.
This means that if you've SSR'ed your footer menu, and you edit that, the HTML page cache won't be invalidated, and your change won't be visible.
A potential fix for this last issue: !177 (diffs)
Edited by boaz