public function CloudFlarePurger::invalidate in CloudFlare 8
Invalidate content from external caches.
Implementations of this method have the responsibility of invalidating the given list of invalidation objects from their external caches. Besides the invalidation itself, it also needs to call ::setState() on each object to reflect the correct state after invalidation.
You can set it to the following states:
- \Drupal\purge\Plugin\Purge\Invalidation\InvStatesInterface::SUCCEEDED
- \Drupal\purge\Plugin\Purge\Invalidation\InvStatesInterface::FAILED
- \Drupal\purge\Plugin\Purge\Invalidation\InvStatesInterface::PROCESSING
- \Drupal\purge\Plugin\Purge\Invalidation\InvStatesInterface::NOT_SUPPORTED
PROCESSING is a special state only intended to be used on caching platforms where more time is required than 1-2 seconds to clear its cache. Usually CDNs with special status API calls where you can later find out if the object succeeded invalidation. When set to this state, the object flows back to the queue to be offered to your plugin again later.
NOT_SUPPORTED will be rarely needed, as invalidation types not listed as supported by your plugin will already be put to this state before it is offered to your plugin by PurgersServiceInterface::invalidate(). However, if there is any technical reason why you couldn't support a particular invalidation at that given time, you can set it as such and it will be offered again later.
Parameters
\Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface[] $invalidations: Non-associative array of invalidation objects that each describe what needs to be invalidated by the external caching system. Usually these objects originate from the queue but direct invalidation is also possible, in either cases the behavior of your plugin stays the same.
The number of objects given is dictated by the outer limit of Purge's capacity tracking mechanism and is dynamically calculated. The lower your ::getTimeHint() implementation returns, the more that will be offered at once. However, your real execution time can and should never exceed the defined hint, to protect system stability.
Overrides PurgerInterface::invalidate
See also
\Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface::setState()
\Drupal\purge\Plugin\Purge\Purger\PurgerCapacityDataInterface::getTimeHint()
File
- modules/
cloudflarepurger/ src/ Plugin/ Purge/ Purger/ CloudFlarePurger.php, line 133
Class
- CloudFlarePurger
- CloudFlare purger.
Namespace
Drupal\cloudflarepurger\Plugin\Purge\PurgerCode
public function invalidate(array $invalidations) {
$chunks = array_chunk($invalidations, CloudFlareAPI::MAX_TAG_PURGES_PER_REQUEST);
$has_invalidations = count($invalidations) > 0;
if (!$has_invalidations) {
return;
}
foreach ($chunks as $chunk) {
$this
->purgeChunk($chunk);
}
}