You are here

protected function CacheCacheTagsChecksum::calculateChecksum in Supercache 2.0.x

Same name and namespace in other branches
  1. 8 src/Cache/CacheCacheTagsChecksum.php \Drupal\supercache\Cache\CacheCacheTagsChecksum::calculateChecksum()

Calculates the current checksum for a given set of tags.

Parameters

array $tags: The array of tags to calculate the checksum for.

Return value

int The calculated checksum.

2 calls to CacheCacheTagsChecksum::calculateChecksum()
CacheCacheTagsChecksum::getCurrentChecksum in src/Cache/CacheCacheTagsChecksum.php
Returns the sum total of validations for a given set of tags.
CacheCacheTagsChecksum::isValid in src/Cache/CacheCacheTagsChecksum.php
Returns whether the checksum is valid for the given cache tags.

File

src/Cache/CacheCacheTagsChecksum.php, line 103
Contains \Drupal\supercache\Cache\CacheCacheTagsChecksum.

Class

CacheCacheTagsChecksum
Cache tags invalidations checksum implementation that uses a CacheRawBackendInterface as the storage.

Namespace

Drupal\supercache\Cache

Code

protected function calculateChecksum(array $tags) {
  $query_tags = array_diff($tags, array_keys($this->tagCache));
  if ($query_tags) {
    $db_tags = array();
    $items = $this->backend
      ->counterGetMultiple($query_tags);
    foreach ($items as $cid => $data) {
      $db_tags[$cid] = $data;
    }

    // If we could not retrieve a tag (because it has never been invalidated) make
    // sure that we initialize it, otherwise the storage backend will keep looking
    // for it once again and again in the persistent backend when using FastChained
    // as the storage.
    $missing_tags = array_diff($query_tags, array_keys($db_tags));
    foreach ($missing_tags as $tag) {

      // Set to the 0 reference value (which is not the initial!)
      $this->backend
        ->counterSet($tag, 0);
    }
    $this->tagCache += $db_tags;

    // Fill static cache with empty objects for tags not found in the database.
    $this->tagCache += array_fill_keys($missing_tags, 0);
  }
  $real_tags = array_intersect_key($this->tagCache, array_flip($tags));
  return array_sum($real_tags);
}