public function ZeroConfigPurger::invalidateUrls in Varnish purger 8.2
Invalidate a set of URL invalidations.
Parameters
\Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface[] $invalidations:
See also
\Drupal\purge\Plugin\Purge\Purger\PurgerInterface::invalidate()
\Drupal\purge\Plugin\Purge\Purger\PurgerInterface::routeTypeToMethod()
File
- src/
Plugin/ Purge/ Purger/ ZeroConfigPurger.php, line 362
Class
- ZeroConfigPurger
- A purger with minimal configuration required.
Namespace
Drupal\varnish_purger\Plugin\Purge\PurgerCode
public function invalidateUrls(array $invalidations) {
$this
->debug(__METHOD__);
// Change all invalidation objects into the PROCESS state before kickoff.
foreach ($invalidations as $inv) {
$inv
->setState(InvalidationInterface::PROCESSING);
}
// Generate request objects for each balancer/invalidation combination.
$ipv4_addresses = $this
->getReverseProxies();
$requests = function () use ($invalidations, $ipv4_addresses) {
foreach ($invalidations as $inv) {
foreach ($ipv4_addresses as $ipv4) {
(yield $inv
->getId() => function ($poolopt) use ($inv, $ipv4) {
$expression = new Uri($inv
->getExpression());
$host = $expression
->getHost();
if ($port = $expression
->getPort()) {
$host .= ':' . $port;
}
$uri = $this
->baseUri($ipv4)
->withPath($expression
->getPath());
$opt = [
'headers' => [
'Accept-Encoding' => 'gzip',
'Host' => $host,
],
];
if (is_array($poolopt) && count($poolopt)) {
$opt = array_merge($poolopt, $opt);
}
return $this->client
->requestAsync('PURGE', $uri, $opt);
});
}
}
};
// Execute the requests generator and retrieve the results.
$results = $this
->getResultsConcurrently('invalidateUrls', $requests);
// Triage the results and set all invalidation states correspondingly.
$this
->triageResults($invalidations, $results);
$this
->debug(__METHOD__);
}