You are here

protected function DatabaseCacheTagsChecksum::calculateChecksum in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php \Drupal\Core\Cache\DatabaseCacheTagsChecksum::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 DatabaseCacheTagsChecksum::calculateChecksum()
DatabaseCacheTagsChecksum::getCurrentChecksum in core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php
Returns the sum total of validations for a given set of tags.
DatabaseCacheTagsChecksum::isValid in core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php
Returns whether the checksum is valid for the given cache tags.

File

core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php, line 110
Contains \Drupal\Core\Cache\DatabaseCacheTagsChecksum.

Class

DatabaseCacheTagsChecksum
Cache tags invalidations checksum implementation that uses the database.

Namespace

Drupal\Core\Cache

Code

protected function calculateChecksum(array $tags) {
  $checksum = 0;
  $query_tags = array_diff($tags, array_keys($this->tagCache));
  if ($query_tags) {
    $db_tags = array();
    try {
      $db_tags = $this->connection
        ->query('SELECT tag, invalidations FROM {cachetags} WHERE tag IN ( :tags[] )', array(
        ':tags[]' => $query_tags,
      ))
        ->fetchAllKeyed();
      $this->tagCache += $db_tags;
    } catch (\Exception $e) {

      // If the table does not exist yet, create.
      if (!$this
        ->ensureTableExists()) {
        $this
          ->catchException($e);
      }
    }

    // Fill static cache with empty objects for tags not found in the database.
    $this->tagCache += array_fill_keys(array_diff($query_tags, array_keys($db_tags)), 0);
  }
  foreach ($tags as $tag) {
    $checksum += $this->tagCache[$tag];
  }
  return $checksum;
}