$cValue = $this->get( $key, $curTTL, $checkKeys, $asOf ); // current value
$value = $cValue; // return value
- // Determine if a regeneration is desired
+ $preCallbackTime = microtime( true );
+ // Determine if a cached value regeneration is needed or desired
if ( $value !== false
&& $curTTL > 0
&& $this->isValid( $value, $versioned, $asOf, $minTime )
&& !$this->worthRefreshExpiring( $curTTL, $lowTTL )
- && !$this->worthRefreshPopular( $asOf, $ageNew, $popWindow )
+ && !$this->worthRefreshPopular( $asOf, $ageNew, $popWindow, $preCallbackTime )
) {
return $value;
}
}
if ( $value !== false && $ttl >= 0 ) {
- // Update the cache; this will fail if the key is tombstoned
$setOpts['lockTSE'] = $lockTSE;
+ // Use best known "since" timestamp if not provided
+ $setOpts += [ 'since' => $preCallbackTime ];
+ // Update the cache; this will fail if the key is tombstoned
$this->set( $key, $value, $ttl, $setOpts );
}
* Example usage:
* @code
* $rows = $cache->getMultiWithSetCallback(
- * // Map of cache keys to entitiy IDs
+ * // Map of cache keys to entity IDs
* $cache->makeMultiKeys(
* $this->fileVersionIds(),
* function ( $id, WANObjectCache $cache ) {
* @param float $asOf UNIX timestamp of the value
* @param integer $ageNew Age of key when this might recommend refreshing (seconds)
* @param integer $timeTillRefresh Age of key when it should be refreshed if popular (seconds)
+ * @param float $now The current UNIX timestamp
* @return bool
*/
- protected function worthRefreshPopular( $asOf, $ageNew, $timeTillRefresh ) {
- $age = microtime( true ) - $asOf;
+ protected function worthRefreshPopular( $asOf, $ageNew, $timeTillRefresh, $now ) {
+ $age = $now - $asOf;
$timeOld = $age - $ageNew;
if ( $timeOld <= 0 ) {
return false;