X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Fobjectcache%2FBagOStuff.php;h=782f4c618e772cb39bf8b024fb98adcc8550b9af;hb=05a4432e2a165844b1295401a62ee313a55a5f2d;hp=ca0e7212ffb1a56ce57346d046e8037bfa54dc34;hpb=bdc88d57e7e10b2554d7cbcf3914113a44c81719;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index ca0e7212ff..782f4c618e 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -185,7 +185,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * * @param string $key * @param int $flags Bitfield of BagOStuff::READ_* constants [optional] - * @param int $oldFlags [unused] + * @param int|null $oldFlags [unused] * @return mixed Returns false on failure and if the item does not exist */ public function get( $key, $flags = 0, $oldFlags = null ) { @@ -343,7 +343,21 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * @throws Exception */ protected function cas( $casToken, $key, $value, $exptime = 0 ) { - throw new Exception( "CAS is not implemented in " . __CLASS__ ); + if ( !$this->lock( $key, 0 ) ) { + return false; // non-blocking + } + + $curCasToken = null; // passed by reference + $this->getWithToken( $key, $curCasToken, self::READ_LATEST ); + if ( $casToken === $curCasToken ) { + $success = $this->set( $key, $value, $exptime ); + } else { + $success = false; // mismatched or failed + } + + $this->unlock( $key ); + + return $success; } /** @@ -357,7 +371,13 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * @return bool Success */ protected function mergeViaLock( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { - if ( !$this->lock( $key, 6 ) ) { + if ( $attempts <= 1 ) { + $timeout = 0; // clearly intended to be "non-blocking" + } else { + $timeout = 3; + } + + if ( !$this->lock( $key, $timeout ) ) { return false; } @@ -760,7 +780,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * * @since 1.27 * @param string $class Key class - * @param string $component [optional] Key component (starting with a key collection name) + * @param string|null $component [optional] Key component (starting with a key collection name) * @return string Colon-delimited list of $keyspace followed by escaped components of $args */ public function makeGlobalKey( $class, $component = null ) { @@ -772,7 +792,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * * @since 1.27 * @param string $class Key class - * @param string $component [optional] Key component (starting with a key collection name) + * @param string|null $component [optional] Key component (starting with a key collection name) * @return string Colon-delimited list of $keyspace followed by escaped components of $args */ public function makeKey( $class, $component = null ) {