function CacheTagsChecksumTrait::isValid

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php \Drupal\Core\Cache\CacheTagsChecksumTrait::isValid()
  2. 8.9.x core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php \Drupal\Core\Cache\CacheTagsChecksumTrait::isValid()
  3. 11.x core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php \Drupal\Core\Cache\CacheTagsChecksumTrait::isValid()

Implements \Drupal\Core\Cache\CacheTagsChecksumInterface::isValid()

File

core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php, line 111

Class

CacheTagsChecksumTrait
A trait for cache tag checksum implementations.

Namespace

Drupal\Core\Cache

Code

public function isValid($checksum, array $tags) {
  // If there are no cache tags, then there is no cache tag to validate,
  // hence it's always valid.
  if (empty($tags)) {
    return TRUE;
  }
  // Any cache reads in this request involving cache tags whose invalidation
  // has been delayed due to an in-progress transaction are not allowed to use
  // data stored in cache; it must be assumed to be stale. This forces those
  // results to be computed instead. Together with the logic in
  // ::getCurrentChecksum(), it also prevents that computed data from being
  // written to the cache.
  if (!empty(array_intersect($tags, $this->delayedTags))) {
    return FALSE;
  }
  return $checksum == $this->calculateChecksum($tags);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.