Redis cache entries not returned due to cache entry checksum issue

Created on 8 September 2025, 11 days ago

On one of our platforms, we experience a strange behavior.
For us it looks like cache entries are stored in redis, but never returned from it, since the cache entries are somehow invalid during the check in \Drupal\Core\Cache\CacheTagsChecksumTrait::isValid():

The following line does return FALSE for most of our entries.
return $checksum == $this->calculateChecksum($tags);

The problem we see is, that \Drupal\Core\Cache\CacheTagsChecksumTrait::calculateChecksum gets the tag invalidation counts. Here redis returns "nil" for almost every entry (question: is this normal, or what could be the reason for this?).

Since redis seems not to have the information about the tag invalidation counts, all nil values are mapped to PHP_INT_MAX (in \Drupal\redis\Cache\RedisCacheTagsChecksum::getTagInvalidationCounts()) which results in the end in a really high checksum.

We see a lot of checksums during cache set/and get like these, which results, if ~100 times PHP_INT_MAX is summed up.

Checksum SET: 1.0883579003488635E+21
Checksum GET: 1.0883579003488635E+21

The problem now is, that this checksum is set in the redis cache entry, but somehow if 1.0883579003488635E+21 is stored and sent to redis, the cacheentry has a slightly different checksum:
$cache->checksum ist hier: 1.0883579003489E+21

So even if 1.0883579003488635E+21 is set, redis stores it as 1.0883579003489E+21 which results in all the cache entry are invalid for that reason.

The fix we made here is return the checksum casted to string in \Drupal\Core\Cache\CacheTagsChecksumTrait::calculateChecksum:

protected function calculateChecksum(array $tags) {
    ...

    return (string) $checksum;
  }

After that change, the cache behaves like expected and returns the cache entries as valid.

Does anyone else had issues like that?

🐛 Bug report
Status

Active

Version

1.10

Component

Code

Created by

🇨🇭Switzerland megadesk3000

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024