CappedMemoryCache
in package
implements
ICache, ArrayAccess
In-memory cache with a capacity limit to keep memory usage in check
Uses a simple FIFO expiry mechanism
Tags
Table of Contents
Interfaces
- ICache
- This interface defines method for accessing the file based user cache.
- ArrayAccess
Properties
Methods
- __construct() : mixed
- clear() : bool
- Clear the user cache of all entries starting with a prefix
- get() : T|null
- Get a value from the user cache
- getData() : array<string|int, T>
- hasKey() : bool
- Check if a value is set in the user cache
- isAvailable() : bool
- Check if the cache implementation is available
- offsetExists() : bool
- offsetGet() : T
- offsetSet() : void
- offsetUnset() : void
- remove() : bool
- Remove an item from the user cache
- set() : bool
- Set a value in the user cache
- garbageCollect() : void
Properties
$cache
private
array<string|int, T>
$cache
= []
$capacity
private
int
$capacity
Methods
__construct()
public
__construct([int $capacity = 512 ]) : mixed
Parameters
- $capacity : int = 512
Tags
clear()
Clear the user cache of all entries starting with a prefix
public
clear([mixed $prefix = '' ]) : bool
Parameters
- $prefix : mixed = ''
-
(optional)
Tags
Return values
boolget()
Get a value from the user cache
public
get(mixed $key) : T|null
Parameters
- $key : mixed
Tags
Return values
T|nullgetData()
public
getData() : array<string|int, T>
Tags
Return values
array<string|int, T>hasKey()
Check if a value is set in the user cache
public
hasKey(mixed $key) : bool
Parameters
- $key : mixed
Tags
Return values
boolisAvailable()
Check if the cache implementation is available
public
static isAvailable() : bool
Tags
Return values
booloffsetExists()
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Tags
Return values
booloffsetGet()
public
& offsetGet(mixed $offset) : T
Parameters
- $offset : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
Return values
ToffsetSet()
public
offsetSet(string $offset, T $value) : void
Parameters
- $offset : string
- $value : T
Tags
offsetUnset()
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
Tags
remove()
Remove an item from the user cache
public
remove(mixed $key) : bool
Parameters
- $key : mixed
Tags
Return values
boolset()
Set a value in the user cache
public
set(string $key, T $value[, int $ttl = 0 ]) : bool
Parameters
- $key : string
- $value : T
- $ttl : int = 0
Tags
Return values
boolgarbageCollect()
private
garbageCollect() : void