X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Flibs%2Fobjectcache%2FBagOStuff.php;h=0dd7b57c6d1a3f29aaa1d5392f7e578ea1cd326c;hp=4fe64f264121c5d840bff69bd1d62e55c58e4666;hb=a38af7ba26579bb3004f673e44d39710887763aa;hpb=3ebb1691397b59266e7c0d69ca44cda6733aea46 diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index 4fe64f2641..0dd7b57c6d 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -175,13 +175,9 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * * @param string $key * @param int $flags Bitfield of BagOStuff::READ_* constants [optional] - * @param int|null $oldFlags [unused] * @return mixed Returns false on failure or if the item does not exist */ - public function get( $key, $flags = 0, $oldFlags = null ) { - // B/C for ( $key, &$casToken = null, $flags = 0 ) - $flags = is_int( $oldFlags ) ? $oldFlags : $flags; - + public function get( $key, $flags = 0 ) { $this->trackDuplicateKeys( $key ); return $this->doGet( $key, $flags ); @@ -223,22 +219,10 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { /** * @param string $key * @param int $flags Bitfield of BagOStuff::READ_* constants [optional] + * @param mixed|null &$casToken Token to use for check-and-set comparisons * @return mixed Returns false on failure or if the item does not exist */ - abstract protected function doGet( $key, $flags = 0 ); - - /** - * @note This method is only needed if merge() uses mergeViaCas() - * - * @param string $key - * @param mixed &$casToken - * @param int $flags Bitfield of BagOStuff::READ_* constants [optional] - * @return mixed Returns false on failure or if the item does not exist - * @throws Exception - */ - protected function getWithToken( $key, &$casToken, $flags = 0 ) { - throw new Exception( __METHOD__ . ' not implemented.' ); - } + abstract protected function doGet( $key, $flags = 0, &$casToken = null ); /** * Set an item @@ -260,6 +244,17 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { */ abstract public function delete( $key, $flags = 0 ); + /** + * Insert an item if it does not already exist + * + * @param string $key + * @param mixed $value + * @param int $exptime + * @param int $flags Bitfield of BagOStuff::WRITE_* constants (since 1.33) + * @return bool Success + */ + abstract public function add( $key, $value, $exptime = 0, $flags = 0 ); + /** * Merge changes into the existing cache value (possibly creating a new one) * @@ -293,13 +288,10 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { */ protected function mergeViaCas( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { do { - $this->clearLastError(); - $reportDupes = $this->reportDupes; - $this->reportDupes = false; $casToken = null; // passed by reference - $currentValue = $this->getWithToken( $key, $casToken, self::READ_LATEST ); - $this->reportDupes = $reportDupes; - + // Get the old value and CAS token from cache + $this->clearLastError(); + $currentValue = $this->doGet( $key, self::READ_LATEST, $casToken ); if ( $this->getLastError() ) { $this->logger->warning( __METHOD__ . ' failed due to I/O error on get() for {key}.', @@ -354,7 +346,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { } $curCasToken = null; // passed by reference - $this->getWithToken( $key, $curCasToken, self::READ_LATEST ); + $this->doGet( $key, self::READ_LATEST, $curCasToken ); if ( $casToken === $curCasToken ) { $success = $this->set( $key, $value, $exptime, $flags ); } else { @@ -587,16 +579,6 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { return $res; } - /** - * Insertion - * @param string $key - * @param mixed $value - * @param int $exptime - * @param int $flags Bitfield of BagOStuff::WRITE_* constants (since 1.33) - * @return bool Success - */ - abstract public function add( $key, $value, $exptime = 0, $flags = 0 ); - /** * Increase stored value of $key by $value while preserving its TTL * @param string $key Key to increase @@ -703,13 +685,21 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { } } + /** + * @param int $exptime + * @return bool + */ + protected function expiryIsRelative( $exptime ) { + return ( $exptime != 0 && $exptime < ( 10 * self::TTL_YEAR ) ); + } + /** * Convert an optionally relative time to an absolute time * @param int $exptime * @return int */ - protected function convertExpiry( $exptime ) { - if ( $exptime != 0 && $exptime < ( 10 * self::TTL_YEAR ) ) { + protected function convertToExpiry( $exptime ) { + if ( $this->expiryIsRelative( $exptime ) ) { return (int)$this->getCurrentTime() + $exptime; } else { return $exptime;