dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Localisation updates from https://translatewiki.net."
[lhc/web/wiklou.git]
/
includes
/
libs
/
ProcessCacheLRU.php
diff --git
a/includes/libs/ProcessCacheLRU.php
b/includes/libs/ProcessCacheLRU.php
index
b55ff9d
..
03e23ed
100644
(file)
--- a/
includes/libs/ProcessCacheLRU.php
+++ b/
includes/libs/ProcessCacheLRU.php
@@
-28,10
+28,10
@@
use Wikimedia\Assert\Assert;
*/
class ProcessCacheLRU {
/** @var Array */
*/
class ProcessCacheLRU {
/** @var Array */
- protected $cache =
array()
; // (key => prop => value)
+ protected $cache =
[]
; // (key => prop => value)
/** @var Array */
/** @var Array */
- protected $cacheTimes =
array()
; // (key => prop => UNIX timestamp)
+ protected $cacheTimes =
[]
; // (key => prop => UNIX timestamp)
protected $maxCacheKeys; // integer; max entries
protected $maxCacheKeys; // integer; max entries
@@
-55,7
+55,7
@@
class ProcessCacheLRU {
*/
public function set( $key, $prop, $value ) {
if ( isset( $this->cache[$key] ) ) {
*/
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 );
} 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 ) {
* @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;
}
return null;
}
+ $this->ping( $key );
+ return $this->cache[$key][$prop];
}
/**
}
/**
@@
-111,8
+109,8
@@
class ProcessCacheLRU {
*/
public function clear( $keys = null ) {
if ( $keys === null ) {
*/
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] );
} 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' );
*/
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 ) {
$this->maxCacheKeys = $maxKeys;
while ( count( $this->cache ) > $this->maxCacheKeys ) {
@@
-151,4
+149,12
@@
class ProcessCacheLRU {
unset( $this->cache[$key] );
$this->cache[$key] = $item;
}
unset( $this->cache[$key] );
$this->cache[$key] = $item;
}
+
+ /**
+ * Get cache size
+ * @return int
+ */
+ public function getSize() {
+ return $this->maxCacheKeys;
+ }
}
}