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

  1. Add an external entity type test and configure it as cacheable
  2. Build a custom module which adds a custom cache tag to test entities in hook_entity_storage_load
  3. Invalidate the custom cache tag manually after loading any test entity
  4. 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.

Command icon 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

rob_pr created an issue. See original summary.

rob_pr’s picture

Status: Active » Needs review

  • 91b1b78f committed on 3.0.x
    Issue #3458277 by rob_pr: Missing custom entity cache tags in...
guignonv’s picture

Status: Needs review » Reviewed & tested by the community

Indeed, 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.

pefferen made their first commit to this issue’s fork.

  • pefferen committed 0ca71ff6 on 8.x-2.x authored by rob_pr
    Issue #3458277 by rob_pr, guignonv: Missing custom entity cache tags in...
pefferen’s picture

Status: Reviewed & tested by the community » Fixed

Nice addition and simplification. Merging to 2.x branch aswell! Thanks @rob_pr

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.