You are here

public function MaxAgeCheck::run in Purge 8.3

Perform the check and determine the severity level.

Diagnostic checks determine whether something you are checking for is in shape, for instance CMI settings on which your plugin depends. Any check reporting self::SEVERITY_ERROR in their run() methods, will cause purge to stop working. Any other severity level will let the purgers proceed operating but you may report any warning through getRecommendation() to be shown on Drupal's status report, purge_ui or any other diagnostic listing.


public function run() {
  if (...check..) {
    return self::SEVERITY_OK;
  }
  return self::SEVERITY_WARNING;
}

@warning As diagnostic checks can be expensive, this method is called as rarely as possible. Checks derived from DiagnosticCheckBase will only see the check getting executed when any of the getter methods are called.

Return value

int Integer, matching either of the following constants:

Throws

\Drupal\purge\Plugin\Purge\DiagnosticCheck\Exception\CheckNotImplementedCorrectly Thrown when the return value is incorrect.

Overrides DiagnosticCheckInterface::run

File

src/Plugin/Purge/DiagnosticCheck/MaxAgeCheck.php, line 60

Class

MaxAgeCheck
Tests if the TTL of your site is in a good shape.

Namespace

Drupal\purge\Plugin\Purge\DiagnosticCheck

Code

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;
  }
}