- 🇫🇷France andypost
Meantime Symfony reverted weak references for DI because of https://github.com/symfony/symfony/issues/50439
Core has a MemoryCache implementation, which provides the same API as cache backends but with everything held in PHP memory.
This is already used for the entity static cache after #1596472: Replace hard coded static cache of entities with cache backends → .
The long term goal is to solve #2558857: Migrations invalidate entity caches when trying to reclaim memory, should flush → 'automatically' - i.e. that core would statically cache things, but that our implementation would prevent memory leaks without intervention. This will solve a lot of issues with processes that need to load lots of entities, with migrate as the main core example #2558857: Migrations invalidate entity caches when trying to reclaim memory, should flush → .
Back in 2011, @catch suggested an implementation using weakreferences - at that time only a PECL extension #1237636-7: Entity lazy multiple front loading → .
There's an issue open to add a basic LRU cache 📌 Add an in-memory LRU cache Needs work implementation (also from 2011), but that has limitations in that there has to be a hard-coded numeric limit on the entities added, which could still lead to out of memory issues in some situations, or entities being ejected from the cache when there's plenty of memory left.
WeakReferences are now in PHP 7.4: https://www.php.net/manual/en/class.weakreference.php
WeakMap is now in PHP 8: https://www.php.net/manual/en/class.weakmap.php / https://wiki.php.net/rfc/weak_maps (can't find actual PHP 8 docs for it yet). With a PHP 7.4 polyfill https://github.com/BenMorel/weakmap-polyfill
Since Drupal 10 will require PHP 8 or higher, we could add an implementation to core in a 9.x minor release, then Drupal 10 could switch the default for entity caching to it.
Load thousands of entities in one go.
Start with a WeakReference implementation for now.
WeakMaps may end up being useful for entity or other caching, but this will require further investigation.
Needs work
11.0 🔥
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Meantime Symfony reverted weak references for DI because of https://github.com/symfony/symfony/issues/50439