Spin-off to prepare for #2155635: Allow plugin managers to opt in to cache clear during module install
Problem
- The static + persistent cache of
FieldInfois not cleared when necessary; e.g., when installing a new module.
Details
FieldInfois an aggregate cache of plugin definitions and configuration data.- It cannot implement the existing
CachedDiscoveryInterfaceof the Plugin component, because that represents a limited and different (discovery) concept only.
Proposed solution
-
Introduce a new
Drupal\Core\State\CachedStateInterface.To be implemented by "manager" classes that are statically/persistently caching state information, which only needs to be rebuilt upon explicit request; i.e., when the application knows that data has changed.
- Make
FieldInfoimplement it. - Rename the existing
flush()method intoclearCachedState() -
→ Allow us to clear the cached state of all corresponding services when e.g. installing/uninstalling a module.
The meat of that is left to #2155635: Allow plugin managers to opt in to cache clear during module install
Notes
In a separate follow-up issue, it would probably be a good idea to revisit the router specific changes from #2164367: Rebuild router as few times as possible per request and move those setRebuildNeeded() + rebuildIfNeeded() + etc methods into this new CachedStateInterface, since that would ultimately give us:
- Enforced state cache clearing.
- On-demand rebuilding upon next access (or end-of-request otherwise).
- A single shared interface for such cached state services (that can be collected through a CompilerPass).
While grepping through core for FieldInfo usages, I noticed that EntityManager has both a clearCachedDefinitions() and a separate clearCachedFieldDefinitions() method, whereas the former does not call into the latter. That is probably a separate "bug" that needs to be fixed as well (but not here).
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | interdiff.txt | 1.18 KB | sun |
| #11 | state.cache_.11.patch | 6.01 KB | sun |
| #8 | interdiff.txt | 5.72 KB | sun |
| #8 | state.cache_.8.patch | 7.2 KB | sun |
| #5 | drupal8.field-info-clear.4.patch | 6.57 KB | sun |
Comments
Comment #2
suneeeek! :-/
Comment #3
sunI already assume there will be reservations to this solution/workaround... ;)
Comment #5
sunNow, the much more appropriate resolution is to decouple the
CachedDiscoveryInterfacefromDiscoveryInterface.Since
PluginManagerInterfacealready implementsDiscoveryInterface, almost no changes are required.Comment #6
tim.plunkettIf we do this, then we need to:
a) Move it out of the Plugin and Discovery namespaces
b) Remove the word "Discovery"
c) Rework #2155635: Allow plugin managers to opt in to cache clear during module install to be about "things that have statically or persistently cached definitions and need them cleared" and not specific to plugin managers at all
We cannot just borrow the interface like this, and masquerade FieldInfo as something related to either plugins or discovery, since it is neither.
I discussed this with @EclipseGc and @neclimdul, and they concurred.
Comment #8
sunAfter some longer discussion in IRC, it appears to be best to leave the
CachedDiscoveryInterfaceconcept of the (decoupled) Plugin component alone.Instead, we introduce a separate/standalone interface for manager classes that are statically/persistently caching state information, which only needs to be rebuilt upon explicit request; i.e., when the application knows that data has changed.
Attached patch adds a new
Drupal\Core\State\CachedStateInterface.In a separate follow-up issue, it would probably be a good idea to revisit the router specific changes from #2164367: Rebuild router as few times as possible per request and move those
setRebuildNeeded()+rebuildIfNeeded()+ etc methods into this newCachedStateInterface, since that would ultimately give us:Comment #9
sunAlso created #2202629: Move Drupal\Core\KeyValueStore\State* into Drupal\Core\State\State*
Comment #10
neclimdulThe old docs are not really about Plugins which is problematic for Drupal\Component so that is a problem. However I'm not sure the new docs really describe the method well outside of the context of this issue.
Rather then holding up this issue on unrelated documentation lets discuss it separately.
Comment #11
sunSure. → Reverted all changes to
CachedDiscoveryInterface.Comment #12
sunAdjusting issue title + summary accordingly.
Comment #13
berdirAs commented in the other issue, field info caches are not the problem. I don't see how it helps us for #2201785: Remove drupal_flush_all_caches() from installer. Field types are.
FieldInfo is also slated to be removed and merged with the EntityManager, see #2116363: Unified repository of field definitions (cache + API). Which would make it part of clearCachedDefinitions() if we want to without requiring any further API changes.
Comment #14
berdirFieldInfo is no more. All field caches are cleared as part of clearCachedDefinitions() on EntityManager.