Documentation

LocalCache
in package
implements Cache, Countable, IteratorAggregate uses ForbidCloning, ForbidSerialization

FinalYes

A cache which stores data in an in-memory (local) array.

This class may be used as a least-recently-used (LRU) cache of a given size. Iterating over the cache will iterate from least-recently-used to most-recently-used.

Tags
template
implements
implements

Table of Contents

Interfaces

Cache
Countable
IteratorAggregate

Properties

$gcCallbackId  : string
$sizeLimit  : int<1, max>|null
$state  : object

Methods

__construct()  : mixed
__destruct()  : mixed
__serialize()  : never
__unserialize()  : never
count()  : int
delete()  : bool|null
Deletes a value associated with the given key if it exists.
get()  : TValue|null
Gets a value associated with the given key.
getIterator()  : Traversable
set()  : void
Sets a value associated with the given key. Overrides existing values (if they exist).
__clone()  : mixed

Properties

$gcCallbackId read-only

private string $gcCallbackId

$sizeLimit read-only

private int<1, max>|null $sizeLimit

Methods

__construct()

public __construct([int<1, max>|null $sizeLimit = null ][, float $gcInterval = 5 ]) : mixed
Parameters
$sizeLimit : int<1, max>|null = null

The maximum size of cache array (number of elements). NULL for unlimited size.

$gcInterval : float = 5

The frequency in seconds at which expired cache entries should be garbage collected.

__unserialize()

public final __unserialize(array<string|int, mixed> $data) : never
Parameters
$data : array<string|int, mixed>
Return values
never

delete()

Deletes a value associated with the given key if it exists.

public delete(string $key) : bool|null

Implementations SHOULD return boolean true or false to indicate whether the specified key existed at the time the delete operation was requested. If such information is not available, the implementation MUST return null.

Implementations MUST NOT error for non-existent keys.

Parameters
$key : string

string Cache key.

Return values
bool|null

Returns true / false to indicate whether the key existed, or null if that information is not available.

get()

Gets a value associated with the given key.

public get(string $key) : TValue|null

If the specified key doesn't exist implementations MUST return null.

Parameters
$key : string

string Cache key.

Return values
TValue|null

Returns the cached value, or null if it doesn't exist

getIterator()

public getIterator() : Traversable
Return values
Traversable

set()

Sets a value associated with the given key. Overrides existing values (if they exist).

public set(string $key, mixed $value[, int|null $ttl = null ]) : void

TTL values less than 0 MUST throw an \Error.

Parameters
$key : string

string Cache key.

$value : mixed

TValue Value to cache.

$ttl : int|null = null

int Timeout in seconds >= 0. The default null $ttl value indicates no timeout.


        
On this page

Search results