Problem/Motivation
Let's take views as a good example; views has 18 plugin types. If we are rendering a view, it could have anywhere from ~10 to all of these. Definitions then need to be loaded for each plugin type. This results in a cache get() call each time.
Proposed resolution
If we could aggregate the data into one cache item, and cache get() once. Then collect sub keys (just regular cache keys for whatever is using the backend) it can return each key directly from the static cache instead of the actual cache.
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 2348245-15.patch | 21.16 KB | swentel |
| #16 | 2348245-15.patch | 21.11 KB | swentel |
| #10 | 2348245-10.patch | 21.11 KB | jibran |
| #10 | interdiff.txt | 2.58 KB | jibran |
Comments
Comment #1
damiankloip commentedThis is a rough, proof of concept patch. Implements a cache collector style backend.
Comment #2
damiankloip commentedRebasing is usually a good idea.
Comment #3
dawehnerLet's start with a nitpick, document it.
Comment #4
dawehnerOn top of that I am not convinced that you should store all the entries in the collection but rather manually configure which one you want to load.
You could save some code here.
It also feels odd to reset all of them, as you could also just invalidate some of them (not for tags.)
It is odd that you request things, even if you just ask for just other CIDs.
did we considered to use the parent functionality of containers here? Note: we could move the plugin ID to the end, and be done.
Comment #5
damiankloip commentedHere is some more work, most of Daniels points addressed. Not the lazy loading though, will look at that later. And how we deal with tags and invalidation in general. I would like this issue to stay as simple as possible from that point of view.
Comment #7
damiankloip commentedAdded an implementation of the generic backend test for this backend. Should make things easier to validate.
Comment #9
jibranHere are some minor doc issues. Do we need profiling here?
more then 80 chars.
more then 8 chars.
Extra space.
space missing after this.
Comment #10
jibranIt'll fix an exception and #9.
Comment #12
dawehnerI'm curious whether the individual cache objects should be stored in $this->storage directly?
When we store the actual objects we could reduce this to array_intersect_keys
We no longer have deleted && invalidated tags, but just the later one.
What is the reason for this array_unique call? Why should an item ever have multiple times the same? At least
\Drupal\Core\Cache\DatabaseBackend::doSetdoes not care about that.Do we need the lazyLoadCache call here?
Ah, so we can't cache the object itself.
Nitpick
I'd not expected this to work, so arguments are appended?
<3
Comment #13
damiankloip commentedGoing to do some work on this.
Comment #14
wim leersComment #15
fabianx commentedSo a question:
What is the difference between \Drupal\Core\Cache\CacheCollectorBackend and \Drupal\Core\Cache\CacheCollector then?
Can / should we consolidate those?
Overall I am +1 to making the Cache Collector a backend instead of a class (CacheArray before).
Comment #16
swentel commentedreroll first, will look at failures and #12 after
Comment #17
swentel commentedUgh, wrong patch
Comment #19
berdirWe can't merge the two, the have a different purpose.
CacheCollector is a generic concept and an abstract class, everything that uses it needs to subclass it to implement certain methods.
Maybe we need to find a better name for this, but not sure what that would be.
Comment #20
catchWe could only do this in a minor release I think given it's an API addition. Since it will save a lot of i/o, bumping to major.
Comment #21
fabianx commented#19: Yes and no, the core CacheCollector class could use - as discussed in IRC - use the CacheCollectorBackend class added here as backend instead and remove a lot of duplicate code.
@Damian also will open a CacheMultipleBackend.php issue, which might be better suited, than a cache collector backend here.
Comment #23
damiankloip commentedAnother approach is something like https://www.drupal.org/node/2473205
Comment #25
dawehnerIMHO we can mark that as a duplicate of #2473205: Create a cache backend that pre loads multiple items in one getMultiple() call now
Comment #26
fabianx commentedI agree to close this as duplicate.