You are here

public function CacheTagsChecksumTrait::invalidateTags in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Cache/CacheTagsChecksumTrait.php \Drupal\Core\Cache\CacheTagsChecksumTrait::invalidateTags()

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

File

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

Class

CacheTagsChecksumTrait
A trait for cache tag checksum implementations.

Namespace

Drupal\Core\Cache

Code

public function invalidateTags(array $tags) {

  // Only invalidate tags once per request unless they are written again.
  foreach ($tags as $key => $tag) {
    if (isset($this->invalidatedTags[$tag])) {
      unset($tags[$key]);
    }
    else {
      $this->invalidatedTags[$tag] = TRUE;
      unset($this->tagCache[$tag]);
    }
  }
  if (!$tags) {
    return;
  }
  $in_transaction = $this
    ->getDatabaseConnection()
    ->inTransaction();
  if ($in_transaction) {
    if (empty($this->delayedTags)) {
      $this
        ->getDatabaseConnection()
        ->addRootTransactionEndCallback([
        $this,
        'rootTransactionEndCallback',
      ]);
    }
    $this->delayedTags = Cache::mergeTags($this->delayedTags, $tags);
  }
  else {
    $this
      ->doInvalidateTags($tags);
  }
}