Merge "Add missing possible errors to ApiRollback.php"
[lhc/web/wiklou.git] / includes / objectcache / APCBagOStuff.php
index 1a0de21..4cbb32d 100644 (file)
  */
 class APCBagOStuff extends BagOStuff {
        /**
-        * @param $key string
+        * @param string $key
+        * @param int $casToken [optional]
         * @return mixed
         */
-       public function get( $key ) {
+       public function get( $key, &$casToken = null ) {
                $val = apc_fetch( $key );
 
+               $casToken = $val;
+
                if ( is_string( $val ) ) {
                        if ( $this->isInteger( $val ) ) {
                                $val = intval( $val );
@@ -46,9 +49,9 @@ class APCBagOStuff extends BagOStuff {
        }
 
        /**
-        * @param $key string
-        * @param $value mixed
-        * @param $exptime int
+        * @param string $key
+        * @param mixed $value
+        * @param int $exptime
         * @return bool
         */
        public function set( $key, $value, $exptime = 0 ) {
@@ -62,8 +65,20 @@ class APCBagOStuff extends BagOStuff {
        }
 
        /**
-        * @param $key string
-        * @param $time int
+        * @param mixed $casToken
+        * @param string $key
+        * @param mixed $value
+        * @param int $exptime
+        * @return bool
+        */
+       public function cas( $casToken, $key, $value, $exptime = 0 ) {
+               // APC's CAS functions only work on integers
+               throw new MWException( "CAS is not implemented in " . __CLASS__ );
+       }
+
+       /**
+        * @param string $key
+        * @param int $time
         * @return bool
         */
        public function delete( $key, $time = 0 ) {
@@ -72,6 +87,17 @@ class APCBagOStuff extends BagOStuff {
                return true;
        }
 
+       /**
+        * @param string $key
+        * @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 ) {
+               return $this->mergeViaLock( $key, $callback, $exptime, $attempts );
+       }
+
        public function incr( $key, $value = 1 ) {
                return apc_inc( $key, $value );
        }
@@ -79,19 +105,4 @@ class APCBagOStuff extends BagOStuff {
        public function decr( $key, $value = 1 ) {
                return apc_dec( $key, $value );
        }
-
-       /**
-        * @return Array
-        */
-       public function keys() {
-               $info = apc_cache_info( 'user' );
-               $list = $info['cache_list'];
-               $keys = array();
-
-               foreach ( $list as $entry ) {
-                       $keys[] = $entry['info'];
-               }
-
-               return $keys;
-       }
 }