Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
MemoryCache backend does not validate the passed cids to invalidateMultiple().
Consequences:
1. It causes a PHP warning: Warning: Creating default object from empty value in Drupal\Core\Cache\MemoryBackend->invalidateMultiple()
.
2. It creates malformed cache item entry. If invalidateTags() gets called after invalidateMultiple() on a malformed cache entry it causes a PHP notice: Notice: Undefined property: stdClass::$tags in Drupal\Core\Cache\MemoryBackend->invalidateTags()
Comment | File | Size | Author |
---|---|---|---|
#6 | drupal-memorycachebackend-invalidatemultiple-ignore-invalid-cids-3017753-6.patch | 1.29 KB | mxr576 |
MemoryBackend_php.png | 298.32 KB | mxr576 |
Comments
Comment #2
mxr576Comment #3
tamasd CreditAttribution: tamasd at Pronovix commentedLGTM
Comment #4
alexpottWe should add a test for this. Let's add
to \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testInvalidate()
Comment #5
alexpottThis could be reduced to
array_walk($cids, [$this, 'invalidate']);
for a bit less complexity since the invalidate method does an isset() check.There'll be less array options i.e. not both array_flip() and array_interset_key() plus less duplicate logic.
Comment #6
mxr576Thanks for the suggestions @alexpott! Good ones! I saw the implementations in this class are fairly simple and I wanted to keep it that way but the
array_walk($cids, [$this, 'invalidate']);
idea is the best solution.Comment #7
borisson_Awesome. This now has testcoverage and all of @alexpott's remarks have been fixed. Setting this to RTBC>
Comment #8
alexpottCommitted and pushed 76bb511174 to 8.7.x and 2047ded936 to 8.6.x. Thanks!