X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flibs%2Fobjectcache%2FHashBagOStuff.php;h=c74bb6e087f51e3c9934fb17330704e27bf93099;hb=50a72860b6eab430160a9504926c6aafa4fb701d;hp=eaea2d15b77b66bed935dcce7e802a7ab590b338;hpb=d5afd5f9096b2c61b5be66e74e633f9e6af78c3c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/objectcache/HashBagOStuff.php b/includes/libs/objectcache/HashBagOStuff.php index eaea2d15b7..c74bb6e087 100644 --- a/includes/libs/objectcache/HashBagOStuff.php +++ b/includes/libs/objectcache/HashBagOStuff.php @@ -49,6 +49,7 @@ class HashBagOStuff extends BagOStuff { * - maxKeys : only allow this many keys (using oldest-first eviction) */ function __construct( $params = [] ) { + $params['segmentationSize'] = $params['segmentationSize'] ?? INF; parent::__construct( $params ); $this->token = microtime( true ) . ':' . mt_rand(); @@ -58,12 +59,10 @@ class HashBagOStuff extends BagOStuff { } } - protected function doGet( $key, $flags = 0 ) { - if ( !$this->hasKey( $key ) ) { - return false; - } + protected function doGet( $key, $flags = 0, &$casToken = null ) { + $casToken = null; - if ( $this->expire( $key ) ) { + if ( !$this->hasKey( $key ) || $this->expire( $key ) ) { return false; } @@ -72,21 +71,12 @@ class HashBagOStuff extends BagOStuff { unset( $this->bag[$key] ); $this->bag[$key] = $temp; - return $this->bag[$key][self::KEY_VAL]; - } - - protected function getWithToken( $key, &$casToken, $flags = 0 ) { - $casToken = null; - - $value = $this->doGet( $key ); - if ( $value !== false ) { - $casToken = $this->bag[$key][self::KEY_CAS]; - } + $casToken = $this->bag[$key][self::KEY_CAS]; - return $value; + return $this->bag[$key][self::KEY_VAL]; } - public function set( $key, $value, $exptime = 0, $flags = 0 ) { + protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) { // Refresh key position for maxCacheKeys eviction unset( $this->bag[$key] ); $this->bag[$key] = [ @@ -105,14 +95,14 @@ class HashBagOStuff extends BagOStuff { } public function add( $key, $value, $exptime = 0, $flags = 0 ) { - if ( $this->get( $key ) === false ) { - return $this->set( $key, $value, $exptime, $flags ); + if ( $this->hasKey( $key ) && !$this->expire( $key ) ) { + return false; // key already set } - return false; // key already set + return $this->doSet( $key, $value, $exptime, $flags ); } - public function delete( $key, $flags = 0 ) { + protected function doDelete( $key, $flags = 0 ) { unset( $this->bag[$key] ); return true; @@ -130,10 +120,6 @@ class HashBagOStuff extends BagOStuff { return false; } - public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { - return $this->mergeViaCas( $key, $callback, $exptime, $attempts, $flags ); - } - /** * Clear all values in cache */ @@ -151,7 +137,7 @@ class HashBagOStuff extends BagOStuff { return false; } - $this->delete( $key ); + $this->doDelete( $key ); return true; } @@ -163,7 +149,7 @@ class HashBagOStuff extends BagOStuff { * @return bool * @since 1.27 */ - protected function hasKey( $key ) { + public function hasKey( $key ) { return isset( $this->bag[$key] ); } }