You are here

public function DatabaseCacheTagsChecksum::invalidateTags in Zircon Profile 8

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

Marks cache items with any of the specified tags as invalid.

Parameters

string[] $tags: The list of tags for which to invalidate cache items.

Overrides CacheTagsInvalidatorInterface::invalidateTags

File

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

Class

DatabaseCacheTagsChecksum
Cache tags invalidations checksum implementation that uses the database.

Namespace

Drupal\Core\Cache

Code

public function invalidateTags(array $tags) {
  try {
    foreach ($tags as $tag) {

      // Only invalidate tags once per request unless they are written again.
      if (isset($this->invalidatedTags[$tag])) {
        continue;
      }
      $this->invalidatedTags[$tag] = TRUE;
      unset($this->tagCache[$tag]);
      $this->connection
        ->merge('cachetags')
        ->insertFields(array(
        'invalidations' => 1,
      ))
        ->expression('invalidations', 'invalidations + 1')
        ->key('tag', $tag)
        ->execute();
    }
  } catch (\Exception $e) {

    // Create the cache table, which will be empty. This fixes cases during
    // core install where cache tags are invalidated before the table is
    // created.
    if (!$this
      ->ensureTableExists()) {
      $this
        ->catchException($e);
    }
  }
}