Merge "Add Special:Mute as a shortcut for muting notifications"
[lhc/web/wiklou.git] / includes / libs / objectcache / WinCacheBagOStuff.php
index 0ca3e4a..9d7e143 100644 (file)
  * @ingroup Cache
  */
 class WinCacheBagOStuff extends BagOStuff {
-       protected function doGet( $key, $flags = 0 ) {
-               $blob = wincache_ucache_get( $key );
-
-               return is_string( $blob ) ? unserialize( $blob ) : false;
-       }
-
-       protected function getWithToken( $key, &$casToken, $flags = 0 ) {
+       protected function doGet( $key, $flags = 0, &$casToken = null ) {
                $casToken = null;
 
                $blob = wincache_ucache_get( $key );
@@ -42,13 +36,11 @@ class WinCacheBagOStuff extends BagOStuff {
                        return false;
                }
 
-               $value = unserialize( $blob );
-               if ( $value === false ) {
-                       return false;
+               $value = $this->unserialize( $blob );
+               if ( $value !== false ) {
+                       $casToken = (string)$blob; // don't bother hashing this
                }
 
-               $casToken = $blob; // don't bother hashing this
-
                return $value;
        }
 
@@ -58,7 +50,7 @@ class WinCacheBagOStuff extends BagOStuff {
                }
 
                $curCasToken = null; // passed by reference
-               $this->getWithToken( $key, $curCasToken, self::READ_LATEST );
+               $this->doGet( $key, self::READ_LATEST, $curCasToken );
                if ( $casToken === $curCasToken ) {
                        $success = $this->set( $key, $value, $exptime, $flags );
                } else {
@@ -75,28 +67,34 @@ class WinCacheBagOStuff extends BagOStuff {
                return $success;
        }
 
-       public function set( $key, $value, $expire = 0, $flags = 0 ) {
-               $result = wincache_ucache_set( $key, serialize( $value ), $expire );
+       protected function doSet( $key, $value, $expire = 0, $flags = 0 ) {
+               $result = wincache_ucache_set( $key, $this->serialize( $value ), $expire );
 
+               // false positive, wincache_ucache_set returns an empty array
+               // in some circumstances.
+               // @phan-suppress-next-line PhanTypeComparisonToArray
                return ( $result === [] || $result === true );
        }
 
        public function add( $key, $value, $exptime = 0, $flags = 0 ) {
-               $result = wincache_ucache_add( $key, serialize( $value ), $exptime );
+               if ( wincache_ucache_exists( $key ) ) {
+                       return false; // avoid warnings
+               }
+
+               $result = wincache_ucache_add( $key, $this->serialize( $value ), $exptime );
 
+               // false positive, wincache_ucache_add returns an empty array
+               // in some circumstances.
+               // @phan-suppress-next-line PhanTypeComparisonToArray
                return ( $result === [] || $result === true );
        }
 
-       public function delete( $key, $flags = 0 ) {
+       protected function doDelete( $key, $flags = 0 ) {
                wincache_ucache_delete( $key );
 
                return true;
        }
 
-       public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
-               return $this->mergeViaCas( $key, $callback, $exptime, $attempts, $flags );
-       }
-
        /**
         * Construct a cache key.
         *