Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
DefaultPluginManager
caches plugin definitions and supports cache tags out of the box. However, it does not implement any API to expose this information, so external code cannot use this metadata to properly control cache invalidation.
Proposed resolution
Make DefaultPluginManager
implement CacheableDependencyInterface
.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#6 | drupal_2720813_6.patch | 3.42 KB | Xano |
#6 | interdiff.txt | 752 bytes | Xano |
Comments
Comment #2
XanoComment #3
XanoComment #5
Wim LeersComment #6
XanoToo bad we can't document this on the interface. Any suggestions for where else this would fit?
Comment #7
dawehnerSo what I'm wondering, does this mean we have issues in existing core which should use that?
Comment #8
XanoYes. Anything based on plugin definitions has no cacheability metadata associated with it, except cached plugin definitions which in many cases use cache tags, but those are internal to plugin managers and not exposed to other code. This patch builds on the existing cache tag functionality to expose it.
This is important for derivative plugins, for instance. Their definitions don't just change when files are updated, but also as a result of CRUD operations on the config entities from which those definitions are derived.
I wonder if we should add
Drupal\Core\Plugin\Discovery\CachedDiscoveryInterface extends Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface, Drupal\Core\Cache\CacheableDependencyInterface
to clearly indicate that if you cache definitions, you'd better tell other code how to interact with those caches.Comment #9
Wim Leers+1 for the principle.
The code looks great.
Cool, I didn't know this PHPUnit assertion!
Comment #10
catchIs there a concrete use case for core that could have a follow-up issue?
Comment #11
Wim LeersYes, there are plenty:
'entity_types'
cache tag is currently being added manually, it should useEntityTypeManager::getCacheTags()
'entity_field_info'
…EntityFieldManager::getCacheTags()
'breakpoints'
…BreakpointManager::getCacheTags()
'contextual_links_plugins'
…ContextualLinkManager::getCacheTags()
'local_action'
…LocalActionManager::getCacheTags()
'local_task'
…LocalTaskManager::getCacheTags()
et cetera. And in fact, any plugin manager that doesn't yet specify a cache tag is kinda buggy in that respect, because AFAICT there's no reason for it not to have cache tags. Which means that anything depending on those plugins currently has incomplete cacheability metadata.
Comment #12
alexpottAs this is an API addition I think we shouldn't add this to 8.1.x. If I'm wrong and this bug should be fixed in 8.1.x then feel free to re-open.
Committed 78bb26d and pushed to 8.2.x. Thanks!
Comment #14
XanoThanks!
I wouldn't say this is an API issue, because it only extends a class to implement an API. I'm not against leaving this out of 8.1.x, although including it will help with performance improvements. The Verf and Plugin modules are able to use this new cacheability metadata already.