You are here

public function FastlyPurger::invalidateTags in Fastly 8.3

Invalidate a set of tags.

Parameters

\Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface[] $invalidations: The invalidator instance.

Throws

\Exception

File

modules/fastlypurger/src/Plugin/Purge/Purger/FastlyPurger.php, line 155

Class

FastlyPurger
Fastly purger.

Namespace

Drupal\fastlypurger\Plugin\Purge\Purger

Code

public function invalidateTags(array $invalidations) {
  $tags = [];

  // Set all invalidation states to PROCESSING before kick off purging.

  /* @var \Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface $invalidation */
  foreach ($invalidations as $invalidation) {
    $invalidation
      ->setState(InvalidationInterface::PROCESSING);
    $tags[] = $invalidation
      ->getExpression();
  }
  if (empty($tags)) {
    foreach ($invalidations as $invalidation) {
      $invalidation
        ->setState(InvalidationInterface::FAILED);
      throw new \Exception('No tag found to purge');
    }
  }

  // Invalidate and update the item state.
  // @TODO: Does Fastly have a limit per purge we need to consider (32k)?
  // Also invalidate the cache tags as hashes, to automatically also work for
  // responses that exceed the 16 KB header limit.
  $hashes = $this->cacheTagsHash
    ->cacheTagsToHashes($tags);
  $invalidation_state = $this
    ->invalidateItems('tags', $hashes);
  $this
    ->updateState($invalidations, $invalidation_state);
}