public function DatabaseCacheTagsChecksum::invalidateTags

public DatabaseCacheTagsChecksum::invalidateTags(array $tags)

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 49

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cache!DatabaseCacheTagsChecksum.php/function/DatabaseCacheTagsChecksum::invalidateTags/8.1.x