Problem/Motivation
We're using two kinds of custom storage clients which extract parent objects as well as nested objects from the response of an external source. Those nested objects are then exposed as individual sub-entities (like paragraphs) referenced by a common parent entity.
When the parent entity is invalidated, we want its sub-entities to be invalidated as well. For this we add the cache tag of the parent entity to the cache tags of each nested entity in hook_entity_storage_load. Unfortunately those custom cache tags are currently ignored by ExternalEntityStorage::setPersistentCache when it stores external entities to the cache backend.
Steps to reproduce
- Add an external entity type test and configure it as cacheable
- Build a custom module which adds a custom cache tag to test entities in hook_entity_storage_load
- Invalidate the custom cache tag manually after loading any test entity
- The cached test entities are unaffected by the invalidation
Proposed resolution
Instead of directly building the entities cache tags in setPersistentCache, call getCacheTags() instead to receive any custom cache tags as well.
Remaining tasks
Review needed.
Issue fork external_entities-3458277
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
rob_pr commentedComment #5
guignonvIndeed, calling ::getCacheTags() if no $this->cacheTags is set will call ::getCacheTagsToInvalidate() which will result in the same behavior as current (before patch)... on v10 at least.
Comment #8
pefferen commentedNice addition and simplification. Merging to 2.x branch aswell! Thanks @rob_pr