- 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium
Just want to post the summary of a discussion I had with @catch here.
MemoryBackend behaves like a proper cache bin in a sense that it always returns a new copy of the cached data. This opposed to MemoryCache that always returns the same object. For this reason we chose not to introduce a factory for MemoryCache nor to tag implementations of said cache with "cache.bin" as we don't want Cache::getBins() to return cache backends that don't really behave like a cache.
As a result of this, we should also not flag BackendChain implementations using MemoryCache as "cache.bin" but rather as "cache_tags_invalidator". This, as the name implies, ensures that caches still get invalidated based on cache tags, but does not allow the service to make it into the list of cache bins. We currently have 2 implementations in book and jsonapi that need updating as such.
Finally, we should also adjust RefreshVariablesTrait to reset instances of MemoryCache that were tagged as cache_tags_invalidator because the moment we rename their tag from "cache.bin" to "cache_tags_invalidator", some browser tests might start failing. As demonstrated in #3376846-26: Implement the new access policy API →
An alternative that was also discussed is to introduce a new tag to flag these "I'm a static cache bin, but not really" type of services, pick those up in ListCacheBinsPass and then also call those from the CacheTagsInvalidator and RefreshVariablesTrait.
With all of the above said, I no longer have any objection to renaming MemoryBackend to something that implies it's to be used in testing only. For all intents and purposes people are encouraged to use MemoryCache, provided we don't let them flag it as a proper cache bin. It's faster in every way and supports cache tags, you just need to treat it as a static in a sense that it always returns the same copy of the cached data (and people might therefore alter it for everyone).
- 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium
Created 📌 Fix MemoryCache discovery and DX Needs review in light of my latest comment. Once that's cleaned up, it should be easier to move people to MemoryCache and then unblock this issue so we can rename MemoryBackend to something more suitable.
- Status changed to Active
about 1 month ago 12:21pm 13 November 2024 - 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium
Yup, to summarize the other issue: We can now use MemoryCache as long as we declare it as cache.bin.memory. Its factory is cache.backend.memory.memory.
Example:
cache.access_policy_memory: class: Drupal\Core\Cache\CacheBackendInterface tags: - { name: cache.bin.memory, default_backend: cache.backend.memory.memory } factory: ['@cache_factory', 'get'] arguments: [access_policy_memory]
This means we should encourage anyone who wasn't using MemoryBackend because of how it works to switch to MemoryCache. We can then rename MemoryBackend to something that implies we only use it in testing to mimic a real cache.
- 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium
Oh wait, #3223580: Use MemoryCache (not MemoryBackend) in the installer → still exists. So back to [PP-1]?
- 🇩🇪Germany geek-merlin Freiburg, Germany
#58: I don't see the other issue blocking this.