SDK for PHP 3.x

LruArrayCache
in package
implements CacheInterface, Countable

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.

Table of Contents

Interfaces

CacheInterface
Represents a simple cache interface.
Countable

Methods

__construct()  : mixed
count()  : int
get()  : mixed|null
Get a cache item by key.
remove()  : mixed
Remove a cache key.
set()  : mixed
Set a cache key value.

Methods

__construct()

public __construct([int $maxItems = 1000 ]) : mixed
Parameters
$maxItems : int = 1000

Maximum number of allowed cache items.

count()

public count() : int
Return values
int

get()

Get a cache item by key.

public get(mixed $key) : mixed|null
Parameters
$key : mixed

Key to retrieve.

Return values
mixed|null

Returns the value or null if not found.

remove()

Remove a cache key.

public remove(mixed $key) : mixed
Parameters
$key : mixed

Key to remove.

set()

Set a cache key value.

public set(mixed $key, mixed $value[, mixed $ttl = 0 ]) : mixed
Parameters
$key : mixed

Key to set

$value : mixed

Value to set.

$ttl : mixed = 0

Number of seconds the item is allowed to live. Set to 0 to allow an unlimited lifetime.

On this page