public function InvalidateCommand::invalidate in Purge 8.3
Directly invalidate an item without going through the queue.
@usage drush p:invalidate tag node:1 Clears URLs tagged with "node:1" from external caching platforms. @usage drush p:invalidate url http://www.drupal.org/ Clears "http://www.drupal.org/" from external caching platforms. @usage drush p:invalidate everything Clears everything on external caching platforms.
@command p:invalidate @aliases pinv,p-invalidate
Parameters
string $type: The type of invalidation to perform, e.g.: tag, path, url.
string|null $expression: The string expression of what needs to be invalidated.
array $options: Associative array of options whose values come from Drush.
1 call to InvalidateCommand::invalidate()
- InvalidateCommand::rebuildExternal in modules/
purge_drush/ src/ Commands/ InvalidateCommand.php - Invalidate 'everything' using the Purge framework.
File
- modules/
purge_drush/ src/ Commands/ InvalidateCommand.php, line 82
Class
- InvalidateCommand
- Directly invalidate an item without going through the queue.
Namespace
Drupal\purge_drush\CommandsCode
public function invalidate($type, $expression = NULL, array $options = [
'format' => 'string',
]) {
// Retrieve our queuer object and fail when it is not returned.
if (!($processor = $this->purgeProcessors
->get('drush_purge_invalidate'))) {
throw new \Exception(dt("Please add the required processor:\ndrush p:processor-add drush_purge_invalidate"));
}
// Instantiate the invalidation object based on user input.
try {
$invalidations = [
$this->purgeInvalidationFactory
->get($type, $expression),
];
} catch (PluginNotFoundException $e) {
throw new \Exception(dt("Type '@type' does not exist, see 'drush p:types' for available types.", [
'@type' => $type,
]));
} catch (InvalidExpressionException $e) {
throw new \Exception($e
->getMessage());
} catch (TypeUnsupportedException $e) {
throw new \Exception(dt("There is no purger supporting '@type', please install one!", [
'@type' => $type,
]));
} catch (MissingExpressionException $e) {
throw new \Exception($e
->getMessage());
}
// Prevent users from accidentally harming their website.
if ($options['format'] === 'string' && $type === 'everything') {
$this
->io()
->caution(dt("Invalidating everything will mass-clear potentially thousands" . " of pages, which could temporarily make your site really slow as" . " external caches will have to warm up again.\n"));
if (!$this
->io()
->confirm(dt("Are you really sure?"))) {
throw new UserAbortException();
}
}
// Attempt the cache invalidation and deal with errors.
try {
$this->purgePurgers
->invalidate($processor, $invalidations);
} catch (DiagnosticsException $e) {
throw new \Exception($e
->getMessage());
} catch (CapacityException $e) {
throw new \Exception($e
->getMessage());
} catch (LockException $e) {
throw new \Exception($e
->getMessage());
}
// Since this command is more meant for testing, we only regard SUCCEEDED as
// a acceptable return state to call success on.
if ($invalidations[0]
->getState() === InvStatesInterface::SUCCEEDED) {
if ($options['format'] === 'string') {
$this
->io()
->success(dt('Item invalidated successfully!'));
}
}
else {
throw new \Exception(dt('Invalidation failed, return state is: @state.', [
'@state' => $invalidations[0]
->getStateString(),
]));
}
}