You are here

protected function CacheTagsChecksumTrait::calculateChecksum in Drupal 8

Same name and namespace in other branches
  1. 9 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 128

Class

CacheTagsChecksumTrait
A trait for cache tag checksum implementations.

Namespace

Drupal\Core\Cache

Code

protected function calculateChecksum(array $tags) {
  $checksum = 0;
  $query_tags = array_diff($tags, 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;
}