MediaWiki REL1_31
|
Handles a simple LRU key/value map with a maximum number of entries. More...
Public Member Functions | |
__construct ( $maxKeys) | |
clear ( $keys=null) | |
Clear one or several cache entries, or all cache entries. | |
get ( $key) | |
Get the value for a key. | |
getAllKeys () | |
getWithSetCallback ( $key, callable $callback, $rank=1.0) | |
Get an item with the given key, producing and setting it if not found. | |
has ( $key) | |
Check if a key exists. | |
set ( $key, $value, $rank=1.0) | |
Set a key/value pair. | |
toArray () | |
Static Public Member Functions | |
static | newFromArray (array $values, $maxKeys) |
Protected Member Functions | |
ping ( $key) | |
Push an entry to the top of the cache. | |
Protected Attributes | |
array | $cache = [] |
$maxCacheKeys | |
Handles a simple LRU key/value map with a maximum number of entries.
Use ProcessCacheLRU if hierarchical purging is needed or objects can become stale
Definition at line 34 of file MapCacheLRU.php.
MapCacheLRU::__construct | ( | $maxKeys | ) |
int | $maxKeys | Maximum number of entries allowed (min 1). |
Exception | When $maxCacheKeys is not an int or not above zero. |
Definition at line 44 of file MapCacheLRU.php.
MapCacheLRU::clear | ( | $keys = null | ) |
Clear one or several cache entries, or all cache entries.
string | array | $keys |
Definition at line 178 of file MapCacheLRU.php.
MapCacheLRU::get | ( | $key | ) |
Get the value for a key.
This returns null if the key is not set. If the item is already set, it will be pushed to the top of the cache.
string | $key |
Definition at line 130 of file MapCacheLRU.php.
MapCacheLRU::getAllKeys | ( | ) |
MapCacheLRU::getWithSetCallback | ( | $key, | |
callable | $callback, | ||
$rank = 1.0 ) |
Get an item with the given key, producing and setting it if not found.
If the callback returns false, then nothing is stored.
string | $key | |
callable | $callback | Callback that will produce the value |
float | $rank | Bottom fraction of the list where keys start off [Default: 1.0] |
Definition at line 159 of file MapCacheLRU.php.
References $value.
MapCacheLRU::has | ( | $key | ) |
Check if a key exists.
string | $key |
Definition at line 114 of file MapCacheLRU.php.
References cache.
|
static |
array | $values | Key/value map in order of increasingly recent access |
int | $maxKeys |
Definition at line 57 of file MapCacheLRU.php.
|
protected |
Push an entry to the top of the cache.
string | $key |
Definition at line 193 of file MapCacheLRU.php.
References cache.
MapCacheLRU::set | ( | $key, | |
$value, | |||
$rank = 1.0 ) |
Set a key/value pair.
This will prune the cache if it gets too large based on LRU. If the item is already set, it will be pushed to the top of the cache.
To reduce evictions due to one-off use of many new keys, $rank can be set to have keys start at the top of a bottom fraction of the list. A value of 3/8 means values start at the top of the bottom 3/8s of the list and are moved to the top of the list when accessed a second time.
string | $key | |
mixed | $value | |
float | $rank | Bottom fraction of the list where keys start off [Default: 1.0] |
Definition at line 89 of file MapCacheLRU.php.
MapCacheLRU::toArray | ( | ) |
Definition at line 70 of file MapCacheLRU.php.
References $cache.
|
protected |
Definition at line 36 of file MapCacheLRU.php.
|
protected |
Definition at line 38 of file MapCacheLRU.php.