Merge "Show no size links on image pages with errors"
[lhc/web/wiklou.git] / includes / objectcache / HashBagOStuff.php
index 26b949f..d061eff 100644 (file)
@@ -34,6 +34,10 @@ class HashBagOStuff extends BagOStuff {
                $this->bag = array();
        }
 
+       /**
+        * @param $key string
+        * @return bool
+        */
        protected function expire( $key ) {
                $et = $this->bag[$key][1];
 
@@ -46,7 +50,12 @@ class HashBagOStuff extends BagOStuff {
                return true;
        }
 
-       function get( $key ) {
+       /**
+        * @param $key string
+        * @param $casToken[optional] mixed
+        * @return bool|mixed
+        */
+       function get( $key, &$casToken = null ) {
                if ( !isset( $this->bag[$key] ) ) {
                        return false;
                }
@@ -55,13 +64,42 @@ class HashBagOStuff extends BagOStuff {
                        return false;
                }
 
+               $casToken = $this->bag[$key][0];
+
                return $this->bag[$key][0];
        }
 
+       /**
+        * @param $key string
+        * @param $value mixed
+        * @param $exptime int
+        * @return bool
+        */
        function set( $key, $value, $exptime = 0 ) {
                $this->bag[$key] = array( $value, $this->convertExpiry( $exptime ) );
+               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
+        * @return bool
+        */
        function delete( $key, $time = 0 ) {
                if ( !isset( $this->bag[$key] ) ) {
                        return false;
@@ -71,9 +109,4 @@ class HashBagOStuff extends BagOStuff {
 
                return true;
        }
-
-       function keys() {
-               return array_keys( $this->bag );
-       }
 }
-