Draft: Add discovery cache backend chain to invalidate in-request plugin definition cache

Problem

Drupal\Core\Plugin\DefaultPluginManager uses DiscoveryCachedTrait::$definitions as an in-request cache of plugin definitions. When a plugin manager uses cache tags and those tags are invalidated, only the persistent cache bin is invalidated; the in-request $definitions cache remains stale for the rest of the request.

Solution

  • Add a cache.discovery_chain backend chain (similar to cache.asset_chain) that combines:
    • cache.memory (in-request, tag-aware)
    • cache.discovery (persistent discovery cache bin)
  • Update default_plugin_manager to use cache.discovery_chain instead of cache.discovery.

This preserves the memory-layer performance benefits while ensuring cache tag invalidation also affects the in-request layer.

Tests

  • Added core/tests/Drupal/KernelTests/Core/Cache/DiscoveryCacheChainTest.php to verify that Cache::invalidateTags() invalidates entries set via cache.discovery_chain.

Files changed

  • core/core.services.yml
  • core/tests/Drupal/KernelTests/Core/Cache/DiscoveryCacheChainTest.php

Closes #3579767

Merge request reports

Loading