Merge "Fix some issues with Microsoft SQL Server support"
[lhc/web/wiklou.git] / includes / objectcache / BagOStuff.php
index 05d897f..56f1be2 100644 (file)
@@ -102,12 +102,12 @@ abstract class BagOStuff {
         * and takes the arguments: (this BagOStuff object, cache key, current value).
         *
         * @param string $key
-        * @param closure $callback Callback method to be executed
+        * @param Closure $callback Callback method to be executed
         * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
         * @param int $attempts The amount of times to attempt a merge in case of failure
         * @return bool Success
         */
-       public function merge( $key, closure $callback, $exptime = 0, $attempts = 10 ) {
+       public function merge( $key, Closure $callback, $exptime = 0, $attempts = 10 ) {
                return $this->mergeViaCas( $key, $callback, $exptime, $attempts );
        }
 
@@ -115,12 +115,12 @@ abstract class BagOStuff {
         * @see BagOStuff::merge()
         *
         * @param string $key
-        * @param closure $callback Callback method to be executed
+        * @param Closure $callback Callback method to be executed
         * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
         * @param int $attempts The amount of times to attempt a merge in case of failure
         * @return bool Success
         */
-       protected function mergeViaCas( $key, closure $callback, $exptime = 0, $attempts = 10 ) {
+       protected function mergeViaCas( $key, Closure $callback, $exptime = 0, $attempts = 10 ) {
                do {
                        $casToken = null; // passed by reference
                        $currentValue = $this->get( $key, $casToken ); // get the old value
@@ -144,12 +144,12 @@ abstract class BagOStuff {
         * @see BagOStuff::merge()
         *
         * @param string $key
-        * @param closure $callback Callback method to be executed
+        * @param Closure $callback Callback method to be executed
         * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
         * @param int $attempts The amount of times to attempt a merge in case of failure
         * @return bool Success
         */
-       protected function mergeViaLock( $key, closure $callback, $exptime = 0, $attempts = 10 ) {
+       protected function mergeViaLock( $key, Closure $callback, $exptime = 0, $attempts = 10 ) {
                if ( !$this->lock( $key, 6 ) ) {
                        return false;
                }
@@ -218,7 +218,7 @@ abstract class BagOStuff {
        /**
         * Delete all objects expiring before a certain date.
         * @param string $date The reference date in MW format
-        * @param callback|bool $progressCallback Optional, a function which will be called
+        * @param callable|bool $progressCallback Optional, a function which will be called
         *     regularly during long-running operations with the percentage progress
         *     as the first parameter.
         *
@@ -247,6 +247,23 @@ abstract class BagOStuff {
                return $res;
        }
 
+       /**
+        * Batch insertion
+        * @param array $data $key => $value assoc array
+        * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
+        * @return bool success
+        * @since 1.24
+        */
+       public function setMulti( array $data, $exptime = 0 ) {
+               $res = true;
+               foreach ( $data as $key => $value ) {
+                       if ( !$this->set( $key, $value, $exptime ) ) {
+                               $res = false;
+                       }
+               }
+               return $res;
+       }
+
        /**
         * @param string $key
         * @param mixed $value
@@ -307,6 +324,23 @@ abstract class BagOStuff {
                return $this->incr( $key, - $value );
        }
 
+       /**
+        * Increase stored value of $key by $value while preserving its TTL
+        *
+        * This will create the key with value $init and TTL $ttl if not present
+        *
+        * @param string $key
+        * @param integer $ttl
+        * @param integer $value
+        * @param integer $init
+        * @return bool
+        * @since 1.24
+        */
+       public function incrWithInit( $key, $ttl, $value = 1, $init = 1 ) {
+               return $this->incr( $key, $value ) ||
+                       $this->add( $key, $init, $ttl ) || $this->incr( $key, $value );
+       }
+
        /**
         * Get the "last error" registered; clearLastError() should be called manually
         * @return int ERR_* constant for the "last error" registry