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
.