LRUCache
in package
Implements a least recently used cache
Tags
Table of Contents
- DEFAULT_SIZE = 200
- Default size of LRU Cache
- $cache : array<string|int, mixed>
- An associative array that represent cache
- $size : int
- Size of the cache
- __construct() : mixed
- Creates an empty cache and sets the size
- get() : mixed
- Returns the value for a given key if found in the cache
- getAll() : array<string|int, mixed>
- Returns all the items currently in cache
- put() : mixed
- Add or update a key with given value to the cache
Constants
DEFAULT_SIZE
Default size of LRU Cache
public
int
DEFAULT_SIZE
= 200
Properties
$cache
An associative array that represent cache
private
array<string|int, mixed>
$cache
$size
Size of the cache
private
int
$size
Methods
__construct()
Creates an empty cache and sets the size
public
__construct([int $size = self::DEFAULT_SIZE ]) : mixed
Parameters
- $size : int = self::DEFAULT_SIZE
-
size of the cache
Return values
mixed —get()
Returns the value for a given key if found in the cache
public
get(mixed $key) : mixed
Parameters
- $key : mixed
-
used to look up value
Return values
mixed —$value if found
getAll()
Returns all the items currently in cache
public
getAll() : array<string|int, mixed>
Return values
array<string|int, mixed> —$this->cache
put()
Add or update a key with given value to the cache
public
put(mixed $key, mixed $value) : mixed
Parameters
- $key : mixed
-
used to look up value
- $value : mixed
-
associated to the key
Return values
mixed —evicted key-value pair if any