Merge "Made BagOStuff::debug protected"
[lhc/web/wiklou.git] / includes / objectcache / BagOStuff.php
index 81c5625..2c10742 100644 (file)
@@ -83,9 +83,6 @@ abstract class BagOStuff implements LoggerAwareInterface {
                $this->debugMode = $bool;
        }
 
-       /* *** THE GUTS OF THE OPERATION *** */
-       /* Override these with functional things in subclasses */
-
        /**
         * Get an item with the given key. Returns false if it does not exist.
         * @param string $key
@@ -103,23 +100,12 @@ abstract class BagOStuff implements LoggerAwareInterface {
         */
        abstract public function set( $key, $value, $exptime = 0 );
 
-       /**
-        * Check and set an item.
-        * @param mixed $casToken
-        * @param string $key
-        * @param mixed $value
-        * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
-        * @return bool Success
-        */
-       abstract public function cas( $casToken, $key, $value, $exptime = 0 );
-
        /**
         * Delete an item.
         * @param string $key
-        * @param int $time Amount of time to delay the operation (mostly memcached-specific)
         * @return bool True if the item was deleted or not found, false on failure
         */
-       abstract public function delete( $key, $time = 0 );
+       abstract public function delete( $key );
 
        /**
         * Merge changes into the existing cache value (possibly creating a new one).
@@ -127,12 +113,16 @@ abstract class BagOStuff implements LoggerAwareInterface {
         * and takes the arguments: (this BagOStuff object, cache key, current value).
         *
         * @param string $key
-        * @param Closure $callback Callback method to be executed
+        * @param callable $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, $callback, $exptime = 0, $attempts = 10 ) {
+               if ( !is_callable( $callback ) ) {
+                       throw new Exception( "Got invalid callback." );
+               }
+
                return $this->mergeViaCas( $key, $callback, $exptime, $attempts );
        }
 
@@ -140,16 +130,17 @@ abstract class BagOStuff implements LoggerAwareInterface {
         * @see BagOStuff::merge()
         *
         * @param string $key
-        * @param Closure $callback Callback method to be executed
+        * @param callable $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, $callback, $exptime = 0, $attempts = 10 ) {
                do {
                        $casToken = null; // passed by reference
-                       $currentValue = $this->get( $key, $casToken ); // get the old value
-                       $value = $callback( $this, $key, $currentValue ); // derive the new value
+                       $currentValue = $this->get( $key, $casToken );
+                       // Derive the new value from the old value
+                       $value = call_user_func( $callback, $this, $key, $currentValue );
 
                        if ( $value === false ) {
                                $success = true; // do nothing
@@ -165,22 +156,33 @@ abstract class BagOStuff implements LoggerAwareInterface {
                return $success;
        }
 
+       /**
+        * Check and set an item.
+        * @param mixed $casToken
+        * @param string $key
+        * @param mixed $value
+        * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
+        * @return bool Success
+        */
+       abstract protected function cas( $casToken, $key, $value, $exptime = 0 );
+
        /**
         * @see BagOStuff::merge()
         *
         * @param string $key
-        * @param Closure $callback Callback method to be executed
+        * @param callable $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, $callback, $exptime = 0, $attempts = 10 ) {
                if ( !$this->lock( $key, 6 ) ) {
                        return false;
                }
 
-               $currentValue = $this->get( $key ); // get the old value
-               $value = $callback( $this, $key, $currentValue ); // derive the new value
+               $currentValue = $this->get( $key );
+               // Derive the new value from the old value
+               $value = call_user_func( $callback, $this, $key, $currentValue );
 
                if ( $value === false ) {
                        $success = true; // do nothing