Simple in-memory LRU cache that limits the number of cached entries.
The LRU cache is implemented using PHP's ordered associative array. When accessing an element, the element is removed from the hash and re-added to ensure that recently used items are always at the end of the list while least recently used are at the beginning. When a value is added to the cache, if the number of cached items exceeds the allowed number, the first N number of items are removed from the array.
__construct ( integer $maxItems = 1000 )
|integer||$maxItems = 1000||Maximum number of allowed cache items.|
mixed|null get ( string $key )
Get a cache item by key.
|string||$key||Key to retrieve.|
Returns the value or null if not found.
set ( string $key, mixed $value, integer $ttl = 0 )
Set a cache key value.
|string||$key||Key to set|
|mixed||$value||Value to set.|
|integer||$ttl = 0||
Number of seconds the item is allowed to live. Set to 0 to allow an unlimited lifetime.
remove ( string $key )
Remove a cache key.
|string||$key||Key to remove.|