class MaxAgeCheck in Purge 8.3
Tests if the TTL of your site is in a good shape.
Plugin annotation
@PurgeDiagnosticCheck(
id = "maxage",
title = @Translation("Page cache max age"),
description = @Translation("Tests if the TTL of your site is in a good shape."),
dependent_queue_plugins = {},
dependent_purger_plugins = {}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase implements DiagnosticCheckInterface
- class \Drupal\purge\Plugin\Purge\DiagnosticCheck\MaxAgeCheck implements DiagnosticCheckInterface
- class \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase implements DiagnosticCheckInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MaxAgeCheck
File
- src/
Plugin/ Purge/ DiagnosticCheck/ MaxAgeCheck.php, line 19
Namespace
Drupal\purge\Plugin\Purge\DiagnosticCheckView source
class MaxAgeCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
/**
* A config object for the system performance configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* Construct a MaxAgeCheck object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @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.
*/
public final function __construct(ConfigFactoryInterface $config_factory, array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->config = $config_factory
->get('system.performance');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('config.factory'), $configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function run() {
$max_age = $this->config
->get('cache.page.max_age');
$this->value = $this
->valueTranslatable($max_age);
if ($max_age === 0) {
$this->recommendation = $this
->t("Your site instructs external caching systems not to cache anything. Not only does this make cache invalidation futile, it is also a great danger to your website as any form of traffic can bring it down quickly!");
return self::SEVERITY_WARNING;
}
elseif ($max_age < 300) {
$this->recommendation = $this
->t("TTL settings below 5 minutes are very dangerous, as sudden traffic increases will quickly reach your webserver(s) and bring Drupal down.");
return self::SEVERITY_WARNING;
}
elseif ($max_age < 86400) {
$this->recommendation = $this
->t("TTL settings under 24 hours are dangerous, as sudden traffic increases will quickly reach your webserver(s) and can make Drupal slow.");
return self::SEVERITY_WARNING;
}
elseif ($max_age < 2764800) {
$this->recommendation = $this
->t("TTL settings under a month are not recommended, the longer you set it, the better your site will perform!");
return self::SEVERITY_WARNING;
}
elseif ($max_age < 31536000) {
$this->recommendation = $this
->t("Consider increasing your TTL to over a year, the better your site will perform!");
return self::SEVERITY_OK;
}
else {
$this->recommendation = $this
->t("Your TTL setting is great!");
return self::SEVERITY_OK;
}
}
/**
* Return a user-facing string that represents the given max_age value.
*
* @param int $max_age
* The max_age setting to format.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The translated value.
*/
protected function valueTranslatable($max_age) {
if ($max_age === 0) {
return $this
->t('no caching');
}
elseif ($max_age === 60) {
return $this
->t('1 minute');
}
elseif ($max_age < 3600) {
return $this
->t('@num minutes', [
'@num' => round($max_age / 60),
]);
}
elseif ($max_age === 3600) {
return $this
->t('1 hour');
}
elseif ($max_age < 86400) {
return $this
->t('@num hours', [
'@num' => round($max_age / 3600, 1),
]);
}
elseif ($max_age === 86400) {
return $this
->t('1 day');
}
elseif ($max_age < 604800) {
return $this
->t('@num days', [
'@num' => round($max_age / 86400, 1),
]);
}
elseif ($max_age === 604800) {
return $this
->t('1 week');
}
elseif ($max_age < 2764800) {
return $this
->t('@num weeks', [
'@num' => round($max_age / 604800, 1),
]);
}
elseif ($max_age === 2764800) {
return $this
->t('1 month');
}
elseif ($max_age < 31536000) {
return $this
->t('@num months', [
'@num' => round($max_age / 2764800, 1),
]);
}
elseif ($max_age === 31536000) {
return $this
->t('1 year');
}
return $this
->t('more than 1 year');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
DiagnosticCheckBase:: |
private | property | The description of the check as described in the plugin's metadata. | |
DiagnosticCheckBase:: |
protected | property | A recommendation matching the severity level, may contain NULL. | |
DiagnosticCheckBase:: |
private | property | The severity of the outcome of this check. | |
DiagnosticCheckBase:: |
private | property | The title of the check as described in the plugin's metadata. | |
DiagnosticCheckBase:: |
protected | property | Optional check outcome / value (e.g. version numbers), may contain NULL. | |
DiagnosticCheckBase:: |
public | function |
Gets the description of the check. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get a recommendation matching the severity level, may return NULL. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Generates a individual Drupal-like requirements array. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level, expressed as a status_report severity. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level as unprefixed string. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Gets the title of the check. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get an optional value for the check output, may return NULL. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
protected | function | Late runtime helper to assure that ::run() got called (and only once). | |
DiagnosticCheckInterface:: |
constant | BLOCKING severity -- Error condition; purge.purgers service cannot operate. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- Informational message only. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- check successfully passed. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- Warning condition; proceed but flag warning. | ||
MaxAgeCheck:: |
protected | property | A config object for the system performance configuration. | |
MaxAgeCheck:: |
public static | function |
Creates an instance of the plugin. Overrides DiagnosticCheckBase:: |
|
MaxAgeCheck:: |
public | function |
Perform the check and determine the severity level. Overrides DiagnosticCheckInterface:: |
|
MaxAgeCheck:: |
protected | function | Return a user-facing string that represents the given max_age value. | |
MaxAgeCheck:: |
final public | function |
Construct a MaxAgeCheck object. Overrides PluginBase:: |
|
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. | |
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. |