You are here

public function CacheTagsChecksumMongodb::calculateChecksum in MongoDB 8

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

File

src/CacheTagsChecksumMongodb.php, line 88
Contains \Drupal\mongodb\CacheTagsChecksumMongodb.

Class

CacheTagsChecksumMongodb

Namespace

Drupal\mongodb

Code

public function calculateChecksum(array $tags) {
  $checksum = 0;
  $query_tags = array_values(array_diff($tags, array_keys($this->tagCache)));
  if ($query_tags) {
    $db_tags = [];
    $result = $this->mongo
      ->get('cachetags')
      ->find([
      'tag' => [
        '$in' => $query_tags,
      ],
    ]);
    foreach ($result as $tag) {
      $db_tags[$tag['tag']] = $tag['invalidations'];
    }
    $this->tagCache += $db_tags;

    // 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;
}