class AkamaiPurger in Akamai 8.3
Akamai Purger.
Plugin annotation
@PurgePurger(
id = "akamai",
label = @Translation("Akamai Purger"),
description = @Translation("Provides a Purge service for Akamai CCU."),
types = {"path", "url", "everything"},
configform = "Drupal\akamai\Form\ConfigForm",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\purge\Plugin\Purge\Purger\PurgerBase implements PurgerInterface uses PurgeLoggerAwareTrait
- class \Drupal\akamai\Plugin\Purge\Purger\AkamaiPurger
- class \Drupal\purge\Plugin\Purge\Purger\PurgerBase implements PurgerInterface uses PurgeLoggerAwareTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of AkamaiPurger
1 file declares its use of AkamaiPurger
- AkamaiPurgerTest.php in tests/
src/ Unit/ Plugin/ Purge/ Purger/ AkamaiPurgerTest.php
File
- src/
Plugin/ Purge/ Purger/ AkamaiPurger.php, line 24
Namespace
Drupal\akamai\Plugin\Purge\PurgerView source
class AkamaiPurger extends PurgerBase {
/**
* Web services client for Akamai API.
*
* @var \Drupal\akamai\AkamaiClient
*/
protected $client;
/**
* Akamai client config.
*
* @var \Drupal\Core\Config
*/
protected $akamaiClientConfig;
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('event_dispatcher'), $container
->get('akamai.client.factory'));
}
/**
* Constructs a \Drupal\Component\Plugin\AkamaiPurger.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The factory for configuration objects.
* @param Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
* @param \Drupal\akamai\AkamaiClientFactory $akamai_client_factory
* The akamai client factory.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, EventDispatcherInterface $event_dispatcher, AkamaiClientFactory $akamai_client_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->client = $akamai_client_factory
->get();
$this->akamaiClientConfig = $config
->get('akamai.settings');
$this->eventDispatcher = $event_dispatcher;
}
/**
* {@inheritdoc}
*/
public function getTimeHint() {
$timeout = (double) $this->akamaiClientConfig
->get('timeout');
// The max value for getTimeHint is 10.00.
if ($timeout > 10) {
return 10;
}
elseif ($timeout > 0) {
return $timeout;
}
return 0;
}
/**
* {@inheritdoc}
*/
public function invalidate(array $invalidations) {
$urls_to_clear = [];
foreach ($invalidations as $invalidation) {
$invalidation
->setState(InvalidationInterface::PROCESSING);
$invalidation_type = $invalidation
->getPluginId();
switch ($invalidation_type) {
case 'path':
$urls_to_clear[] = $this
->normalizePath($invalidation
->getExpression());
break;
case 'url':
// URL invalidations should be of type
// \Drupal\purge\Plugin\Purge\Invalidation\UrlInvalidation.
try {
// This SHOULD be an internal path, but in some cases, like
// when a database is moved between environments, might not be.
$url = $invalidation
->getUrl()
->getInternalPath();
} catch (\UnexpectedValueException $e) {
$url = $this
->normalizePath($invalidation
->getUrl()
->getUri());
}
$urls_to_clear[] = $url;
break;
}
}
// Instantiate event and alter tags with subscribers.
$event = new AkamaiPurgeEvents($urls_to_clear);
$this->eventDispatcher
->dispatch(AkamaiPurgeEvents::PURGE_CREATION, $event);
$urls_to_clear = $event->data;
// Purge all URLs in a single request. Akamai accepts up to 50 (?)
// invalidations per request.
if ($this->client
->purgeUrls($urls_to_clear)) {
// Now mark all URLs as cleared.
foreach ($invalidations as $invalidation) {
$invalidation
->setState(InvalidationInterface::SUCCEEDED);
}
}
}
/**
* Use a static value for purge queuer performance.
*
* @todo investigate whether we can track performance asynchronously.
*
* @see parent::hasRunTimeMeasurement()
*/
public function hasRuntimeMeasurement() {
return FALSE;
}
/**
* Converts any path or URL into a normalized path.
*
* @param string $url
* URL to normalize.
*
* @return string
* Path suitable for passing to AkamaiClient, like my/path?myquery=str.
*/
public function normalizePath($url) {
$parsed_url = parse_url($url);
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
return $path . $query;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AkamaiPurger:: |
protected | property | Akamai client config. | |
AkamaiPurger:: |
protected | property | Web services client for Akamai API. | |
AkamaiPurger:: |
protected | property | The event dispatcher. | |
AkamaiPurger:: |
public static | function |
Creates an instance of the plugin. Overrides PurgerBase:: |
|
AkamaiPurger:: |
public | function |
Get the maximum number of seconds, processing a single invalidation takes. Overrides PurgerBase:: |
|
AkamaiPurger:: |
public | function |
Use a static value for purge queuer performance. Overrides PurgerCapacityDataInterface:: |
|
AkamaiPurger:: |
public | function |
Invalidate content from external caches. Overrides PurgerInterface:: |
|
AkamaiPurger:: |
public | function | Converts any path or URL into a normalized path. | |
AkamaiPurger:: |
public | function |
Constructs a \Drupal\Component\Plugin\AkamaiPurger. Overrides PurgerBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PurgeLoggerAwareTrait:: |
protected | property | Channel logger. | |
PurgeLoggerAwareTrait:: |
public | function | ||
PurgerBase:: |
protected | property | Unique instance ID for this purger. | |
PurgerBase:: |
protected | property | The runtime measurement counter. | |
PurgerBase:: |
public | function |
The current instance of this purger plugin is about to be deleted. Overrides PurgerInterface:: |
1 |
PurgerBase:: |
public | function |
Get the time in seconds to wait after invalidation. Overrides PurgerCapacityDataInterface:: |
|
PurgerBase:: |
public | function |
Retrieve the unique instance ID for this purger instance. Overrides PurgerInterface:: |
|
PurgerBase:: |
public | function |
Get the maximum number of invalidations that this purger can process. Overrides PurgerCapacityDataInterface:: |
1 |
PurgerBase:: |
public | function |
Retrieve the user-readable label for this purger instance. Overrides PurgerInterface:: |
|
PurgerBase:: |
public | function |
Get the runtime measurement counter. Overrides PurgerCapacityDataInterface:: |
|
PurgerBase:: |
public | function |
Retrieve the list of supported invalidation types. Overrides PurgerInterface:: |
|
PurgerBase:: |
public | function |
Route certain type of invalidations to other methods. Overrides PurgerInterface:: |
|
PurgerBase:: |
public | function |
Inject the runtime measurement counter. Overrides PurgerCapacityDataInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |