Problem/Motivation
The decision tree of CacheFactory::get() looks like this:
1) Use cache bin specific backend configuration if available
2) Use configured default cache backend
3) Use cache bin default backend
4) Database backend.
The fact that it uses the default cache backend (2) before the cache bin default backend (3) causes problems when setting a default cache backend, e.g. redis:
a) For example cache.static suddenly uses redis and persists and is no longer a static/memory cache.
b) discovery/config/bootstrap no longer use the fast chained backend by default but go directly to redis.
This can result in unexpected behavior and performance regressions when using redis, as you get a lot more cache hits against redis for the fast chained backends.
Proposed resolution
Switch the order of 2 and 3. That's a behavior change, but I think it makes sense and based on how core uses the default cache backend, it expects that this wins unless someone *explicitly* overrides it.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#9 | cache-factory-get-order-2753989-9.patch | 3.54 KB | Berdir |
#9 | cache-factory-get-order-2753989-9-test-only.patch | 2.33 KB | Berdir |
#2 | cache-factory-get-order-2753989-2.patch | 1.21 KB | Berdir |
Comments
Comment #2
BerdirAnd here is a patch.
Comment #3
Fabianx CreditAttribution: Fabianx as a volunteer commentedRTBC - Fully agree, I just had the same problem with FileCache, too.
Comment #4
Fabianx CreditAttribution: Fabianx as a volunteer commentedComment #5
BerdirThanks, will create a change record. Not sure if we need some (unit) tests to enforce this order?
Comment #6
Fabianx CreditAttribution: Fabianx as a volunteer commented#5: I think some unit tests would be great to have here. Someone writing a test would probably have found the behavior as it would be odd writing a test for the wrong thing.
Comment #7
BerdirOk, setting back to needs work for that.
Comment #8
Fabianx CreditAttribution: Fabianx as a volunteer commentedComment #9
BerdirOk, improved the tests. We had the three other cases tested but only always on their own. This also tests the per-bin default and makes sure the correct order is used.
Comment #10
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRTBC - Nice work!
Comment #13
BerdirThose are really weird test fails...
Comment #14
BerdirTest fails that the patch had:
Comment #15
BerdirChange record created: https://www.drupal.org/node/2754947
Was RTBC before failing with those fails which I assume are random, it also passed already for PHP 7.
Comment #16
Wim LeersSeems completely sensible!
Comment #17
dawehnerWow, yeah that is quite of a WTF. +1
I checked similar subsystems, queue, lock KV to see whether they contain similar code, they don't.
Comment #19
catchFixed on commit.
Committed/pushed to 8.2.x. Leaving this fixed against that branch, since there's a tiny chance that an 8.1.x site is relying on the current behaviour (like dead code in settings.php which this would re-activate).
Comment #20
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedPublished the change record.
Comment #22
Wim LeersThis failed to update documentation. Which caused a new bug report to be filed: #2820580: Drupal >=8.2.x doesn't allow to override all cache bins with $settings['cache']['default'] anymore, documentation says otherwise.