X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2FProcessCacheLRU.php;h=03e23edbb753b0f8cc8d506657b9cb41a7b3d22a;hb=f97b82ee6beccab638dbaa659e666b0fbc79b1dd;hp=b55ff9da8b9dfab4c900989547c18e8084d58649;hpb=8c087b9fd13d9302ec1be2176ef1ae344b3f8273;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/ProcessCacheLRU.php b/includes/libs/ProcessCacheLRU.php index b55ff9da8b..03e23edbb7 100644 --- a/includes/libs/ProcessCacheLRU.php +++ b/includes/libs/ProcessCacheLRU.php @@ -28,10 +28,10 @@ use Wikimedia\Assert\Assert; */ class ProcessCacheLRU { /** @var Array */ - protected $cache = array(); // (key => prop => value) + protected $cache = []; // (key => prop => value) /** @var Array */ - protected $cacheTimes = array(); // (key => prop => UNIX timestamp) + protected $cacheTimes = []; // (key => prop => UNIX timestamp) protected $maxCacheKeys; // integer; max entries @@ -55,7 +55,7 @@ class ProcessCacheLRU { */ public function set( $key, $prop, $value ) { if ( isset( $this->cache[$key] ) ) { - $this->ping( $key ); // push to top + $this->ping( $key ); } elseif ( count( $this->cache ) >= $this->maxCacheKeys ) { reset( $this->cache ); $evictKey = key( $this->cache ); @@ -94,13 +94,11 @@ class ProcessCacheLRU { * @return mixed */ public function get( $key, $prop ) { - if ( isset( $this->cache[$key][$prop] ) ) { - // push to top - $this->ping( $key ); - return $this->cache[$key][$prop]; - } else { + if ( !isset( $this->cache[$key][$prop] ) ) { return null; } + $this->ping( $key ); + return $this->cache[$key][$prop]; } /** @@ -111,8 +109,8 @@ class ProcessCacheLRU { */ public function clear( $keys = null ) { if ( $keys === null ) { - $this->cache = array(); - $this->cacheTimes = array(); + $this->cache = []; + $this->cacheTimes = []; } else { foreach ( (array)$keys as $key ) { unset( $this->cache[$key] ); @@ -130,7 +128,7 @@ class ProcessCacheLRU { */ public function resize( $maxKeys ) { Assert::parameterType( 'integer', $maxKeys, '$maxKeys' ); - Assert::parameter( $maxKeys >= 1, '$maxKeys', 'must be >= 1' ); + Assert::parameter( $maxKeys > 0, '$maxKeys', 'must be above zero' ); $this->maxCacheKeys = $maxKeys; while ( count( $this->cache ) > $this->maxCacheKeys ) { @@ -151,4 +149,12 @@ class ProcessCacheLRU { unset( $this->cache[$key] ); $this->cache[$key] = $item; } + + /** + * Get cache size + * @return int + */ + public function getSize() { + return $this->maxCacheKeys; + } }