Merge "Omit RC_EXTERNAL edits from UDP feed"
[lhc/web/wiklou.git] / includes / objectcache / HashBagOStuff.php
index ff07884..d061eff 100644 (file)
@@ -52,9 +52,10 @@ class HashBagOStuff extends BagOStuff {
 
        /**
         * @param $key string
+        * @param $casToken[optional] mixed
         * @return bool|mixed
         */
-       function get( $key ) {
+       function get( $key, &$casToken = null ) {
                if ( !isset( $this->bag[$key] ) ) {
                        return false;
                }
@@ -63,6 +64,8 @@ class HashBagOStuff extends BagOStuff {
                        return false;
                }
 
+               $casToken = $this->bag[$key][0];
+
                return $this->bag[$key][0];
        }
 
@@ -77,6 +80,21 @@ class HashBagOStuff extends BagOStuff {
                return true;
        }
 
+       /**
+        * @param $casToken mixed
+        * @param $key string
+        * @param $value mixed
+        * @param $exptime int
+        * @return bool
+        */
+       function cas( $casToken, $key, $value, $exptime = 0 ) {
+               if ( $this->get( $key ) === $casToken ) {
+                       return $this->set( $key, $value, $exptime );
+               }
+
+               return false;
+       }
+
        /**
         * @param $key string
         * @param $time int
@@ -92,4 +110,3 @@ class HashBagOStuff extends BagOStuff {
                return true;
        }
 }
-