You are here

protected function CapacityTracker::gatherCooldownTimes in Purge 8.3

Gather ::getCooldownTime() data by iterating all loaded purgers.

2 calls to CapacityTracker::gatherCooldownTimes()
CapacityTracker::getCooldownTime in src/Plugin/Purge/Purger/CapacityTracker.php
Get the time in seconds to wait after invalidation for a specific purger.
CapacityTracker::getCooldownTimeTotal in src/Plugin/Purge/Purger/CapacityTracker.php
Get the time in seconds to wait after invalidation for all purgers.

File

src/Plugin/Purge/Purger/CapacityTracker.php, line 107

Class

CapacityTracker
Provides the capacity tracker.

Namespace

Drupal\purge\Plugin\Purge\Purger

Code

protected function gatherCooldownTimes() {
  if (is_null($this->cooldownTimes)) {
    if (is_null($this->purgers)) {
      throw new \LogicException("::setPurgers() hasn't been called!");
    }
    $this->cooldownTimes = [];
    foreach ($this->purgers as $id => $purger) {
      $cooldown_time = $purger
        ->getCooldownTime();
      if (!is_float($cooldown_time)) {
        $method = sprintf("%s::getCooldownTime()", get_class($purger));
        throw new BadPluginBehaviorException("{$method} did not return a floating point value.");
      }
      if ($cooldown_time < 0.0) {
        $method = sprintf("%s::getCooldownTime()", get_class($purger));
        throw new BadPluginBehaviorException("{$method} returned {$cooldown_time}, a value lower than 0.0.");
      }
      if ($cooldown_time > 3.0) {
        $method = sprintf("%s::getCooldownTime()", get_class($purger));
        throw new BadPluginBehaviorException("{$method} returned {$cooldown_time}, a value higher than 3.0.");
      }
      $this->cooldownTimes[$id] = $cooldown_time;
    }
  }
}