public function CapacityTracker::getLeaseTimeHint in Purge 8.3
Estimate how long a call to ::invalidate() takes for X amount of objects.
Parameters
int $items: The number of objects about to be offered to the purgers service.
Return value
int The number of seconds cache invalidation will take for this many items.
Throws
\Drupal\purge\Plugin\Purge\Purger\Exception\BadBehaviorException Thrown when $number_of_objects is lower than 1 or not an integer.
Overrides CapacityTrackerInterface::getLeaseTimeHint
See also
\Drupal\purge\Plugin\Purge\Purger\CapacityTrackerInterface::getTimeHintTotal()
\Drupal\purge\Plugin\Purge\Purger\CapacityTrackerInterface::getCooldownTimeTotal()
File
- src/
Plugin/ Purge/ Purger/ CapacityTracker.php, line 227
Class
- CapacityTracker
- Provides the capacity tracker.
Namespace
Drupal\purge\Plugin\Purge\PurgerCode
public function getLeaseTimeHint($items) {
if ($items < 1 || !is_int($items)) {
throw new BadPluginBehaviorException('$items is below 1 or no integer.');
}
// Create a closure that calculates how much time it would take. It takes
// cooldown time as well as potential code overhead into account.
$calculate = function ($items) {
$s = $items * $this
->getTimeHintTotal() + $this
->getCooldownTimeTotal();
$s++;
return (int) ceil($s);
};
// Use the items number as cache key and fetch/add calculations from/to it.
if (!isset($this->leaseTimeHints[$items])) {
$this->leaseTimeHints[$items] = $calculate($items);
}
return $this->leaseTimeHints[$items];
}