public function ZeroConfigPurger::invalidateEverything in Varnish purger 8.2
Invalidate the entire website.
This supports invalidation objects of the type 'everything'. Because many load balancers on Acquia Cloud host multiple websites (e.g. sites in a multisite) this will only affect the current site instance. This works because all Varnish-cached resources are tagged with a unique identifier coming from hostingInfo::getSiteIdentifier().
See also
\Drupal\purge\Plugin\Purge\Purger\PurgerInterface::invalidate()
\Drupal\purge\Plugin\Purge\Purger\PurgerInterface::routeTypeToMethod()
File
- src/
Plugin/ Purge/ Purger/ ZeroConfigPurger.php, line 469
Class
- ZeroConfigPurger
- A purger with minimal configuration required.
Namespace
Drupal\varnish_purger\Plugin\Purge\PurgerCode
public function invalidateEverything(array $invalidations) {
$this
->debug(__METHOD__);
// Set the 'everything' object(s) into processing mode.
foreach ($invalidations as $invalidation) {
$invalidation
->setState(InvalidationInterface::PROCESSING);
}
// Fetch the site identifier and start with a successive outcome.
$overall_success = TRUE;
// Synchronously request each balancer to wipe out everything for this site.
foreach ($this
->getReverseProxies() as $ip_address) {
try {
$uri = $this
->baseUri($ip_address);
$uri = $uri
->withPath('/.*');
$options = [
'headers' => [
'Host' => \Drupal::request()
->getHost(),
'Accept-Encoding' => 'gzip',
],
];
$this->client
->request('BAN', $uri, $this
->getGlobalOptions($options));
} catch (\Exception $e) {
$this
->logFailedRequest('invalidateEverything', $e);
$overall_success = FALSE;
}
}
// Set the object states according to our overall result.
foreach ($invalidations as $invalidation) {
if ($overall_success) {
$invalidation
->setState(InvalidationInterface::SUCCEEDED);
}
else {
$invalidation
->setState(InvalidationInterface::FAILED);
}
}
$this
->debug(__METHOD__);
}