Merge "Fix some issues with Microsoft SQL Server support"
[lhc/web/wiklou.git] / includes / objectcache / HashBagOStuff.php
index 799f26a..db0e579 100644 (file)
@@ -35,7 +35,7 @@ class HashBagOStuff extends BagOStuff {
        }
 
        /**
-        * @param $key string
+        * @param string $key
         * @return bool
         */
        protected function expire( $key ) {
@@ -51,10 +51,11 @@ class HashBagOStuff extends BagOStuff {
        }
 
        /**
-        * @param $key string
+        * @param string $key
+        * @param mixed $casToken [optional]
         * @return bool|mixed
         */
-       function get( $key ) {
+       function get( $key, &$casToken = null ) {
                if ( !isset( $this->bag[$key] ) ) {
                        return false;
                }
@@ -63,13 +64,15 @@ class HashBagOStuff extends BagOStuff {
                        return false;
                }
 
+               $casToken = serialize( $this->bag[$key][0] );
+
                return $this->bag[$key][0];
        }
 
        /**
-        * @param $key string
-        * @param $value mixed
-        * @param $exptime int
+        * @param string $key
+        * @param mixed $value
+        * @param int $exptime
         * @return bool
         */
        function set( $key, $value, $exptime = 0 ) {
@@ -78,8 +81,23 @@ class HashBagOStuff extends BagOStuff {
        }
 
        /**
-        * @param $key string
-        * @param $time int
+        * @param mixed $casToken
+        * @param string $key
+        * @param mixed $value
+        * @param int $exptime
+        * @return bool
+        */
+       function cas( $casToken, $key, $value, $exptime = 0 ) {
+               if ( serialize( $this->get( $key ) ) === $casToken ) {
+                       return $this->set( $key, $value, $exptime );
+               }
+
+               return false;
+       }
+
+       /**
+        * @param string $key
+        * @param int $time
         * @return bool
         */
        function delete( $key, $time = 0 ) {
@@ -91,12 +109,4 @@ class HashBagOStuff extends BagOStuff {
 
                return true;
        }
-
-       /**
-        * @return array
-        */
-       function keys() {
-               return array_keys( $this->bag );
-       }
 }
-