*
* @ingroup Cache
*/
-abstract class BagOStuff implements LoggerAwareInterface {
+abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
/** @var array[] Lock tracking */
protected $locks = array();
do {
$this->clearLastError();
$casToken = null; // passed by reference
- $currentValue = $this->getWithToken( $key, $casToken, BagOStuff::READ_LATEST );
+ $currentValue = $this->getWithToken( $key, $casToken, self::READ_LATEST );
if ( $this->getLastError() ) {
return false; // don't spam retries (retry only on races)
}
}
$this->clearLastError();
- $currentValue = $this->get( $key, BagOStuff::READ_LATEST );
+ $currentValue = $this->get( $key, self::READ_LATEST );
if ( $this->getLastError() ) {
$success = false;
} else {
}
}
- $expiry = min( $expiry ?: INF, 86400 );
+ $expiry = min( $expiry ?: INF, self::TTL_DAY );
$this->clearLastError();
$timestamp = microtime( true ); // starting UNIX timestamp
} elseif ( $this->getLastError() || $timeout <= 0 ) {
$locked = false; // network partition or non-blocking
} else {
- $uRTT = ceil( 1e6 * ( microtime( true ) - $timestamp ) ); // estimate RTT (us)
+ // Estimate the RTT (us); use 1ms minimum for sanity
+ $uRTT = max( 1e3, ceil( 1e6 * ( microtime( true ) - $timestamp ) ) );
$sleep = 2 * $uRTT; // rough time to do get()+set()
$attempts = 0; // failed attempts
* @since 1.26
*/
final public function getScopedLock( $key, $timeout = 6, $expiry = 30, $rclass = '' ) {
- $expiry = min( $expiry ?: INF, 86400 );
+ $expiry = min( $expiry ?: INF, self::TTL_DAY );
if ( !$this->lock( $key, $timeout, $expiry, $rclass ) ) {
return null;
* @return int
*/
protected function convertExpiry( $exptime ) {
- if ( ( $exptime != 0 ) && ( $exptime < 86400 * 3650 /* 10 years */ ) ) {
+ if ( $exptime != 0 && $exptime < ( 10 * self::TTL_YEAR ) ) {
return time() + $exptime;
} else {
return $exptime;
* @return int
*/
protected function convertToRelative( $exptime ) {
- if ( $exptime >= 86400 * 3650 /* 10 years */ ) {
+ if ( $exptime >= ( 10 * self::TTL_YEAR ) ) {
$exptime -= time();
if ( $exptime <= 0 ) {
$exptime = 1;
* @return string
*/
public function makeKeyInternal( $keyspace, $args ) {
- $key = $keyspace . ':' . implode( ':', $args );
+ $key = $keyspace;
+ foreach ( $args as $arg ) {
+ $arg = str_replace( ':', '%3A', $arg );
+ $key = $key . ':' . $arg;
+ }
return strtr( $key, ' ', '_' );
}