Closed (fixed)
Project:
Drupal core
Version:
11.4.x-dev
Component:
render system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Jun 2026 at 08:26 UTC
Updated:
17 Jun 2026 at 16:25 UTC
Jump to comment: Most recent
Comments
Comment #3
longwaveCould we swap the $themeHandler argument in the constructor for the parameter, because the theme handler isn't needed otherwise.
Comment #4
longwaveAlternatively, we could do this with cache tags? (which means injecting the invalidator instead)
Comment #5
catchOh good spot, I initially wondered about that then quickly convinced myself that that theme handler is the same as the theme manager... which it obviously isn't. I think we can swap it yeah and check the type in the constructor.
Using cache tags we used to do until #3335768: Manually clear cache keys from plugin managers with finite variations instead of using cache tags and I think we should still err on not using them for these nearly but not quite 1-1 caches.
Comment #6
longwavedrupal_flush_all_caches():
Why do we need the plugin cache clear after we just wiped all bins?
edit: and given that we clear statics and rebuild the container if no kernel is passed in:
then any static caches inside plugin manager services should be gone too.
Comment #7
longwaveI just did some manual instrumentation and by the time we get to
the only plugin manager with any data is the entity type manager, and that's only because
BlockHooks::rebuild()validates regions for all blocks.So, perhaps we can just drop this?!
Comment #8
catchIt may possibly be worth switching to the container extension list anyway, but we probably can't eliminate it on these requests so it may not make any appreciable difference.
Dropping this entirely sounds great, I started to look at that but missed that the container rebuild would drop everything before we get here.
The block hooks one is a reload so that's OK, and also opened #3593204: Remove BlockHooks::rebuild() for that too because it's quite strange code (that we added in 2008).
Comment #9
longwaveIf we don't do that we should try reordering as follows:
This is because hook_rebuild primes the entity type manager cache (and perhaps others, depending on what's installed), then that immediately gets cleared again, then during route rebuild the entity type manager (and again, maybe others) are primed for a second time.
This is also out of scope for this particular issue and I should just create a followup :)
Comment #10
catchPushed a commit with just the plugin cache clear removal to see what happens to our wonderful test suite.
It looks like we can nearly deprecate/remove the plugin cache clearer service if it works. One usage in search help but that probably should be clearing the search plugin cache or similar.
Comment #11
longwaveThis is green! But we should probably look why this was added where it was, in case there is some edge case we're missing...
Comment #12
longwaveI asked Claude to do some research, here's a summary of what it found:
2013:
#1892462: EntityManager should use the CacheDecorator added
plugin.manager.entity->clearCachedDefinitions()under a comment@todo Rebuild the kernel/container#1982984: Create Drupal::entityManager for improved DX changed this to
Drupal::entityManager()->clearCachedDefinitions()2014:
#2155635: Allow plugin managers to opt in to cache clear during module install adds the
plugin.cache_clearerservice#2326409: Annotate render element plugins generalises the single entity manager flush to use
plugin.cache_clearerinstead2015:
#2493665: Add centralized container invalidation method fixes the original @todo
Now that we rebuild the container on cache clear and also module install, it looks like the original reason for
plugin.cache_clearerto exist might be gone.Comment #13
longwaveNo, we still need the plugin cache clearer for the module/theme install/uninstall scenarios, because those don't wipe the discovery cache bins. But I still think it's safe to drop from
drupal_flush_all_caches().Comment #14
catchI think we could do that in a follow-up - discovery tables are largely plugins, not a lot else in them.
Comment #15
catchComment #16
longwaveComment #17
catchOpened #3593204: Remove BlockHooks::rebuild() and #3593415: Deprecate PluginCacheClearer for the other things discovered here.
Comment #18
alexpottI've had a think about drupal_rebuild() and the way it passes the kernel into drupal_flush_all_caches (to prevent unnecessary rebuilds). I think this is fine because there is no way for services to pollute their statics from cache here. Well there is one potential place - there's the \Drupal\Core\DrupalKernelInterface::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED event - this event is very poorly named - but it does not trigger on rebuild.php because the request is not on the stack when the container is rebuilt.
Comment #19
alexpottCommitted and pushed 0394ef0b0ab to main and f0da424363b to 11.x and e94fef706cf to 11.4.x. Thanks!