Class LruArrayCache
- Aws\LruArrayCache implements Aws\CacheInterface, Countable
- Namespace: Aws
- Located at LruArrayCache.php
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.
Methods Summary
- __construct ( int $maxItems = 1000 )
-
get ( string $key )
Get a cache item by key.
-
set ( string $key, mixed $value, int $ttl = 0 )
Set a cache key value.
-
remove ( string $key )
Remove a cache key.
- count ( )
Methods Details
__construct ( integer $maxItems = 1000 )
Parameters
integer | $maxItems = 1000 | Maximum number of allowed cache items. |
mixed|null get ( string $key )
Get a cache item by key.
Parameters
string | $key | Key to retrieve. |
Returns
mixed|null Returns the value or null if not found. |
Implementation of
set ( string $key, mixed $value, integer $ttl = 0 )
Set a cache key value.
Parameters
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. |
Implementation of
remove ( string $key )
Remove a cache key.
Parameters
string | $key | Key to remove. |
Implementation of
count ( )
Implementation of
Countable::count()