function CacheTagsChecksumTrait::calculateChecksum
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php \Drupal\Core\Cache\CacheTagsChecksumTrait::calculateChecksum()
- 8.9.x core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php \Drupal\Core\Cache\CacheTagsChecksumTrait::calculateChecksum()
- 10 core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php \Drupal\Core\Cache\CacheTagsChecksumTrait::calculateChecksum()
Calculates the current checksum for a given set of tags.
Parameters
string[] $tags: The array of tags to calculate the checksum for.
Return value
int The calculated checksum.
2 calls to CacheTagsChecksumTrait::calculateChecksum()
- CacheTagsChecksumTrait::getCurrentChecksum in core/
lib/ Drupal/ Core/ Cache/ CacheTagsChecksumTrait.php - Implements \Drupal\Core\Cache\CacheTagsChecksumInterface::getCurrentChecksum()
- CacheTagsChecksumTrait::isValid in core/
lib/ Drupal/ Core/ Cache/ CacheTagsChecksumTrait.php - Implements \Drupal\Core\Cache\CacheTagsChecksumInterface::isValid()
File
-
core/
lib/ Drupal/ Core/ Cache/ CacheTagsChecksumTrait.php, line 139
Class
- CacheTagsChecksumTrait
- A trait for cache tag checksum implementations.
Namespace
Drupal\Core\CacheCode
protected function calculateChecksum(array $tags) {
$checksum = 0;
// If there are no cache tags, then there is no cache tag to checksum,
// so return early.
if (empty($tags)) {
return $checksum;
}
// If there are registered preload tags, add them to the tags list then
// reset the list. This needs to make sure that it only returns the
// requested cache tags, so store the combination of requested and
// preload cache tags in a separate variable.
$tags_with_preload = $tags;
if ($this->preloadTags) {
$tags_with_preload = array_unique(array_merge($tags, $this->preloadTags));
$this->preloadTags = [];
}
$query_tags = array_diff($tags_with_preload, array_keys($this->tagCache));
if ($query_tags) {
$tag_invalidations = $this->getTagInvalidationCounts($query_tags);
$this->tagCache += $tag_invalidations;
// Fill static cache with empty objects for tags not found in the storage.
$this->tagCache += array_fill_keys(array_diff($query_tags, array_keys($tag_invalidations)), 0);
}
foreach ($tags as $tag) {
$checksum += $this->tagCache[$tag];
}
return $checksum;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.