/** @var callable|null Function that takes a WAN cache callback and runs it later */
protected $asyncHandler;
- /** @bar bool Whether to use mcrouter key prefixing for routing */
+ /** @var bool Whether to use mcrouter key prefixing for routing */
protected $mcrouterAware;
/** @var string Physical region for mcrouter use */
protected $region;
* @note Options added in 1.33: creating
* @note Options added in 1.34: version, walltime
* @return bool Success
- * @suppress PhanTypeInvalidDimOffset
*/
final public function set( $key, $value, $ttl = self::TTL_INDEFINITE, array $opts = [] ) {
$now = $this->getCurrentTime();
* @note Options added in 1.31: staleTTL, graceTTL
* @note Options added in 1.33: touchedCallback
* @note Callable type hints are not used to avoid class-autoloading
- * @suppress PhanTypeInvalidDimOffset
*/
final public function getWithSetCallback( $key, $ttl, $callback, array $opts = [] ) {
$version = $opts['version'] ?? null;
// Nested callback process cache use is not lag-safe with regard to HOLDOFF_TTL since
// process cached values are more lagged than persistent ones as they are not purged.
if ( $pCache && $this->callbackDepth == 0 ) {
- $cached = $pCache->get( $this->getProcessCacheKey( $key, $version ), INF, false );
+ $cached = $pCache->get( $this->getProcessCacheKey( $key, $version ), $pcTTL, false );
if ( $cached !== false ) {
return $cached;
}
$this->setInterimValue( $key, $value, $lockTSE, $version, $walltime );
} else {
$finalSetOpts = [
- // @phan-suppress-next-line PhanTypeInvalidDimOffset
'since' => $setOpts['since'] ?? $preCallbackTime,
'version' => $version,
'staleTTL' => $staleTTL,
$chance = ( 1 - $curTTL / $lowTTL );
+ // @phan-suppress-next-line PhanTypeMismatchArgumentInternal
return mt_rand( 1, 1e9 ) <= 1e9 * $chance;
}
// Ramp up $chance from 0 to its nominal value over RAMPUP_TTL seconds to avoid stampedes
$chance *= ( $timeOld <= self::$RAMPUP_TTL ) ? $timeOld / self::$RAMPUP_TTL : 1;
+ // @phan-suppress-next-line PhanTypeMismatchArgumentInternal
return mt_rand( 1, 1e9 ) <= 1e9 * $chance;
}
*/
private function determineKeyClassForStats( $key ) {
$parts = explode( ':', $key, 3 );
-
- return $parts[1] ?? $parts[0]; // sanity
+ // Sanity fallback in case the key was not made by makeKey.
+ // Replace dots because they are special in StatsD (T232907)
+ return strtr( $parts[1] ?? $parts[0], '.', '_' );
}
/**
if ( !isset( $this->processCaches[$group] ) ) {
list( , $size ) = explode( ':', $group );
$this->processCaches[$group] = new MapCacheLRU( (int)$size );
+ if ( $this->wallClockOverride !== null ) {
+ $this->processCaches[$group]->setMockTime( $this->wallClockOverride );
+ }
}
return $this->processCaches[$group];
public function setMockTime( &$time ) {
$this->wallClockOverride =& $time;
$this->cache->setMockTime( $time );
+ foreach ( $this->processCaches as $pCache ) {
+ $pCache->setMockTime( $time );
+ }
}
}