Use tagged iterator in plugin.cache_clearer instead of a lazy service

Created on 21 March 2024, 8 months ago
Updated 10 June 2024, 5 months ago

Problem/Motivation

  plugin.cache_clearer:
    class: Drupal\Core\Plugin\CachedDiscoveryClearer
    lazy: true

However the service is always instantiated and used directly so the lazy proxy is pointless:

\Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();

Even worse, the service is not lazily instantiated anyway:

> $proxy = \Drupal::service('plugin.cache_clearer');
= Drupal\Core\ProxyClass\Plugin\CachedDiscoveryClearer {#8061}

> (new ReflectionProperty($proxy, 'service'))->getValue($proxy);
= Drupal\Core\Plugin\CachedDiscoveryClearer {#8062}

The $service property should not be set until a method is called on the actual service, but the addCachedDiscovery method calls configured in PluginManagerPass trigger the instantiation of the real service as soon as the proxy service is created.

Steps to reproduce

Proposed resolution

Remove the lazy proxy. Use a tagged iterator instead of calls to addCachedDiscovery.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

11.0 πŸ”₯

Component
PluginΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024