You are here

protected function DatabaseCacheTagsChecksum::doInvalidateTags in Drupal 9

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

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

Parameters

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

Overrides CacheTagsChecksumTrait::doInvalidateTags

File

core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php, line 35

Class

DatabaseCacheTagsChecksum
Cache tags invalidations checksum implementation that uses the database.

Namespace

Drupal\Core\Cache

Code

protected function doInvalidateTags(array $tags) {
  try {
    foreach ($tags as $tag) {
      $this->connection
        ->merge('cachetags')
        ->insertFields([
        '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);
    }
  }
}