MediaWiki  master
MapCacheLRU Class Reference

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. More...
 
 get ($key)
 Get the value for a key. More...
 
 getAllKeys ()
 
 getWithSetCallback ($key, callable $callback)
 Get an item with the given key, producing and setting it if not found. More...
 
 has ($key)
 Check if a key exists. More...
 
 set ($key, $value)
 Set a key/value pair. More...
 

Protected Member Functions

 ping ($key)
 Push an entry to the top of the cache. More...
 

Protected Attributes

array $cache = []
 
 $maxCacheKeys
 

Detailed Description

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

See also
ProcessCacheLRU
Since
1.23

Definition at line 34 of file MapCacheLRU.php.

Constructor & Destructor Documentation

MapCacheLRU::__construct (   $maxKeys)
Parameters
int$maxKeysMaximum number of entries allowed (min 1).
Exceptions
ExceptionWhen $maxCacheKeys is not an int or not above zero.

Definition at line 44 of file MapCacheLRU.php.

Member Function Documentation

MapCacheLRU::clear (   $keys = null)

Clear one or several cache entries, or all cache entries.

Parameters
string | array$keys
Returns
void

Definition at line 139 of file MapCacheLRU.php.

References $key, $keys, array(), as, and cache.

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.

Parameters
string$key
Returns
mixed Returns null if the key was not found

Definition at line 92 of file MapCacheLRU.php.

References $key, cache, has(), and ping().

MapCacheLRU::getAllKeys ( )
Returns
array
Since
1.25

Definition at line 106 of file MapCacheLRU.php.

References cache.

MapCacheLRU::getWithSetCallback (   $key,
callable  $callback 
)

Get an item with the given key, producing and setting it if not found.

If the callback returns false, then nothing is stored.

Since
1.28
Parameters
string$key
callable$callbackCallback that will produce the value
Returns
mixed The cached value if found or the result of $callback otherwise

Definition at line 120 of file MapCacheLRU.php.

References $key, $value, has(), and set().

MapCacheLRU::has (   $key)

Check if a key exists.

Parameters
string$key
Returns
bool

Definition at line 77 of file MapCacheLRU.php.

References $key, and cache.

Referenced by get(), getWithSetCallback(), and set().

MapCacheLRU::ping (   $key)
protected

Push an entry to the top of the cache.

Parameters
string$key

Definition at line 154 of file MapCacheLRU.php.

References $key, and cache.

Referenced by get(), and set().

MapCacheLRU::set (   $key,
  $value 
)

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.

Parameters
string$key
mixed$value
Returns
void

Definition at line 60 of file MapCacheLRU.php.

References $key, $value, cache, has(), key, and ping().

Referenced by getWithSetCallback().

Member Data Documentation

array MapCacheLRU::$cache = []
protected

Definition at line 36 of file MapCacheLRU.php.

MapCacheLRU::$maxCacheKeys
protected

Definition at line 38 of file MapCacheLRU.php.


The documentation for this class was generated from the following file: