You are here

public function CapacityTracker::getIdealConditionsLimit in Purge 8.3

Get the maximum number of invalidations that can be processed.

External cache invalidation is expensive and can become exponentially more expensive when multiple platforms are being invalidated. To assure that we don't purge more than request lifetime allows for, ::getTimeHintTotal() gives the highest number of seconds a cache invalidation could take.

A call to ::getRemainingInvalidationsLimit() calculates how many cache invalidations are left to be processed during this request. It bases its decision on ::getMaxExecutionTime() and ::getIdealConditionsLimit() and information tracked during request lifetime. When it returns zero, no more items can be claimed from the queue or fed to the purgers service.

In order to track this global limit, ::decrementLimit() gets called every time the purgers service attempted one or more invalidations until the value becomes zero.

Return value

int The number of invalidations that can be processed under ideal conditions.

Throws

\Drupal\purge\Plugin\Purge\Purger\Exception\BadPluginBehaviorException Thrown when a returned value is not a integer or when it equals to 0.

Overrides CapacityTrackerInterface::getIdealConditionsLimit

See also

\Drupal\purge\Plugin\Purge\Purger\PurgerCapacityDataInterface::getIdealConditionsLimit()

1 call to CapacityTracker::getIdealConditionsLimit()
CapacityTracker::getRemainingInvalidationsLimit in src/Plugin/Purge/Purger/CapacityTracker.php
Get the remaining number of allowed cache invalidations for this request.

File

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

Class

CapacityTracker
Provides the capacity tracker.

Namespace

Drupal\purge\Plugin\Purge\Purger

Code

public function getIdealConditionsLimit() {
  if (is_null($this->idealConditionsLimit)) {
    if (is_null($this->purgers)) {
      throw new \LogicException("::setPurgers() hasn't been called!");
    }

    // Fail early when no purgers are loaded.
    if (empty($this->purgers)) {
      $this->idealConditionsLimit = 0;
      return $this->idealConditionsLimit;
    }

    // Find the lowest emitted ideal conditions limit.
    $this->idealConditionsLimit = [];
    foreach ($this->purgers as $purger) {
      $limit = $purger
        ->getIdealConditionsLimit();
      if (!is_int($limit) || $limit < 1) {
        $method = sprintf("%s::getIdealConditionsLimit()", get_class($purger));
        throw new BadPluginBehaviorException("{$method} returned {$limit}, which has to be a integer higher than 0.");
      }
      $this->idealConditionsLimit[] = $limit;
    }
    $this->idealConditionsLimit = (int) min($this->idealConditionsLimit);
  }
  return $this->idealConditionsLimit;
}