Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / libs / objectcache / BagOStuff.php
index 4fe64f2..0dd7b57 100644 (file)
@@ -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;