From 149e397fbeb47faff84f6b0ee928fa975671356b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 25 Sep 2014 12:04:09 -0700 Subject: [PATCH] Improved timestamp precision in ProcessCacheLRU Change-Id: I42f27df4ec9f944bd308e13eb832d84f1d9492a9 --- includes/libs/ProcessCacheLRU.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/libs/ProcessCacheLRU.php b/includes/libs/ProcessCacheLRU.php index f988207a89..ce97142d77 100644 --- a/includes/libs/ProcessCacheLRU.php +++ b/includes/libs/ProcessCacheLRU.php @@ -61,7 +61,7 @@ class ProcessCacheLRU { unset( $this->cacheTimes[$evictKey] ); } $this->cache[$key][$prop] = $value; - $this->cacheTimes[$key][$prop] = time(); + $this->cacheTimes[$key][$prop] = microtime( true ); } /** @@ -69,12 +69,13 @@ class ProcessCacheLRU { * * @param $key string * @param $prop string - * @param $maxAge integer Ignore items older than this many seconds (since 1.21) + * @param $maxAge float Ignore items older than this many seconds (since 1.21) * @return bool */ - public function has( $key, $prop, $maxAge = 0 ) { + public function has( $key, $prop, $maxAge = 0.0 ) { if ( isset( $this->cache[$key][$prop] ) ) { - return ( $maxAge <= 0 || ( time() - $this->cacheTimes[$key][$prop] ) <= $maxAge ); + return ( $maxAge <= 0 || + ( microtime( true ) - $this->cacheTimes[$key][$prop] ) <= $maxAge ); } return false; @@ -121,6 +122,7 @@ class ProcessCacheLRU { * * @param $maxKeys integer * @return void + * @throws UnexpectedValueException */ public function resize( $maxKeys ) { if ( !is_int( $maxKeys ) || $maxKeys < 1 ) { -- 2.20.1