X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2FMapCacheLRU.php;h=ad5e58d8082f328dd43a1f9639cdd650b19950c4;hb=a075271157d32567e894c668aa2b76138c491b95;hp=bca8c05a36a38f98b17e7f5615a32a584c035538;hpb=4b5773a4de8156c026be2aab92e059793d612fdd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/MapCacheLRU.php b/includes/libs/MapCacheLRU.php index bca8c05a36..ad5e58d808 100644 --- a/includes/libs/MapCacheLRU.php +++ b/includes/libs/MapCacheLRU.php @@ -135,7 +135,7 @@ class MapCacheLRU implements IExpiringStore, Serializable { * Check if a key exists * * @param string $key - * @param float $maxAge Ignore items older than this many seconds (since 1.32) + * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32) * @return bool */ public function has( $key, $maxAge = 0.0 ) { @@ -157,10 +157,11 @@ class MapCacheLRU implements IExpiringStore, Serializable { * If the item is already set, it will be pushed to the top of the cache. * * @param string $key - * @return mixed Returns null if the key was not found + * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32) + * @return mixed Returns null if the key was not found or is older than $maxAge */ - public function get( $key ) { - if ( !$this->has( $key ) ) { + public function get( $key, $maxAge = 0.0 ) { + if ( !$this->has( $key, $maxAge ) ) { return null; } @@ -193,7 +194,7 @@ class MapCacheLRU implements IExpiringStore, Serializable { /** * @param string|int $key * @param string|int $field - * @param float $maxAge + * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32) * @return bool */ public function hasField( $key, $field, $maxAge = 0.0 ) { @@ -205,8 +206,18 @@ class MapCacheLRU implements IExpiringStore, Serializable { return ( $maxAge <= 0 || $this->getAge( $key, $field ) <= $maxAge ); } - public function getField( $key, $field ) { - return $this->get( $key )[$field] ?? null; + /** + * @param string|int $key + * @param string|int $field + * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32) + * @return mixed Returns null if the key was not found or is older than $maxAge + */ + public function getField( $key, $field, $maxAge = 0.0 ) { + if ( !$this->hasField( $key, $field, $maxAge ) ) { + return null; + } + + return $this->cache[$key][$field]; } /** @@ -247,11 +258,11 @@ class MapCacheLRU implements IExpiringStore, Serializable { /** * Clear one or several cache entries, or all cache entries * - * @param string|array $keys + * @param string|array|null $keys * @return void */ public function clear( $keys = null ) { - if ( $keys === null ) { + if ( func_num_args() == 0 ) { $this->cache = []; $this->timestamps = []; } else {