Merge "Fix WatchedItemStore last-seen stashing logic"
[lhc/web/wiklou.git] / includes / libs / objectcache / BagOStuff.php
index 2f10708..c439f9b 100644 (file)
@@ -267,6 +267,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
         * (which will be false if not present), and takes the arguments:
         * (this BagOStuff, cache key, current value, TTL).
         * The TTL parameter is reference set to $exptime. It can be overriden in the callback.
+        * If the callback returns false, then the current value will be unchanged (including TTL).
         *
         * @param string $key
         * @param callable $callback Callback method to be executed
@@ -463,7 +464,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
                        function () use ( $key, $expiry, $fname ) {
                                $this->clearLastError();
                                if ( $this->add( "{$key}:lock", 1, $expiry ) ) {
-                                       return true; // locked!
+                                       return WaitConditionLoop::CONDITION_REACHED; // locked!
                                } elseif ( $this->getLastError() ) {
                                        $this->logger->warning(
                                                $fname . ' failed due to I/O error for {key}.',
@@ -606,6 +607,22 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
                return $res;
        }
 
+       /**
+        * Batch deletion
+        * @param string[] $keys List of keys
+        * @param int $flags Bitfield of BagOStuff::WRITE_* constants
+        * @return bool Success
+        * @since 1.33
+        */
+       public function deleteMulti( array $keys, $flags = 0 ) {
+               $res = true;
+               foreach ( $keys as $key ) {
+                       $res = $this->delete( $key, $flags ) && $res;
+               }
+
+               return $res;
+       }
+
        /**
         * Insertion
         * @param string $key
@@ -614,14 +631,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
         * @param int $flags Bitfield of BagOStuff::WRITE_* constants (since 1.33)
         * @return bool Success
         */
-       public function add( $key, $value, $exptime = 0, $flags = 0 ) {
-               // @note: avoid lock() here since that method uses *this* method by default
-               if ( $this->get( $key ) === false ) {
-                       return $this->set( $key, $value, $exptime, $flags );
-               }
-
-               return false; // key already set
-       }
+       abstract public function add( $key, $value, $exptime = 0, $flags = 0 );
 
        /**
         * Increase stored value of $key by $value while preserving its TTL