Documentation

ArrayAdapter
in package
implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface uses LoggerAwareTrait

An in-memory cache storage.

Acts as a least-recently-used (LRU) storage when configured with a maximum number of items.

Tags
author

Nicolas Grekas p@tchwork.com

Table of Contents

Interfaces

AdapterInterface
Interface for adapters managing instances of Symfony's CacheItem.
CacheInterface
Covers most simple to advanced caching needs.
LoggerAwareInterface
Describes a logger-aware instance.
ResettableInterface
Resets a pool's local state.

Properties

$logger  : LoggerInterface|null
The logger instance.
$createCacheItem  : Closure
$defaultLifetime  : int
$expiries  : array<string|int, mixed>
$maxItems  : int
$maxLifetime  : float
$storeSerialized  : bool
$tags  : array<string|int, mixed>
$values  : array<string|int, mixed>

Methods

__construct()  : mixed
clear()  : bool
Deletes all items in the pool.
commit()  : bool
Persists any deferred cache items.
delete()  : bool
Removes an item from the pool.
deleteItem()  : bool
Removes the item from the pool.
deleteItems()  : bool
Removes multiple items from the pool.
get()  : T
Fetches a value from the pool or computes it if not found.
getItem()  : CacheItemInterface
Returns a Cache Item representing the specified key.
getItems()  : iterable<string, CacheItem>
Returns a traversable set of cache items.
getValues()  : array<string|int, mixed>
Returns all cached values, with cache miss as null.
hasItem()  : bool
Confirms if the cache contains specified cache item.
reset()  : void
save()  : bool
Persists a cache item immediately.
saveDeferred()  : bool
Sets a cache item to be persisted later.
setLogger()  : mixed
Sets a logger.
freeze()  : string|int|float|bool|array<string|int, mixed>|UnitEnum|null
generateItems()  : Generator
unfreeze()  : mixed
validateKeys()  : bool

Properties

$createCacheItem

private static Closure $createCacheItem

$expiries

private array<string|int, mixed> $expiries = []

Methods

__construct()

public __construct([int $defaultLifetime = 0 ][, bool $storeSerialized = true ][, float $maxLifetime = 0 ][, int $maxItems = 0 ]) : mixed
Parameters
$defaultLifetime : int = 0
$storeSerialized : bool = true

Disabling serialization can lead to cache corruptions when storing mutable values but increases performance otherwise

$maxLifetime : float = 0
$maxItems : int = 0

clear()

Deletes all items in the pool.

public clear([string $prefix = '' ]) : bool
Parameters
$prefix : string = ''
Return values
bool

True if the pool was successfully cleared. False if there was an error.

commit()

Persists any deferred cache items.

public commit() : bool
Return values
bool

True if all not-yet-saved items were successfully saved or there were none. False otherwise.

delete()

Removes an item from the pool.

public delete(string $key) : bool
Parameters
$key : string

The key to delete

Return values
bool

True if the item was successfully removed, false if there was any error

deleteItem()

Removes the item from the pool.

public deleteItem(mixed $key) : bool
Parameters
$key : mixed

The key to delete.

Return values
bool

True if the item was successfully removed. False if there was an error.

deleteItems()

Removes multiple items from the pool.

public deleteItems(array<string|int, mixed> $keys) : bool
Parameters
$keys : array<string|int, mixed>

An array of keys that should be removed from the pool.

Return values
bool

True if the items were successfully removed. False if there was an error.

get()

Fetches a value from the pool or computes it if not found.

public get(string $key, callable $callback[, float|null $beta = null ][, array<string|int, mixed>|null &$metadata = null ]) : T

On cache misses, a callback is called that should return the missing value. This callback is given a PSR-6 CacheItemInterface instance corresponding to the requested key, that could be used e.g. for expiration control. It could also be an ItemInterface instance when its additional features are needed.

Parameters
$key : string

The key of the item to retrieve from the cache

$callback : callable
$beta : float|null = null

A float that, as it grows, controls the likeliness of triggering early expiration. 0 disables it, INF forces immediate expiration. The default (or providing null) is implementation dependent but should typically be 1.0, which should provide optimal stampede protection. See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration

$metadata : array<string|int, mixed>|null = null

The metadata of the cached item ItemInterface::getMetadata()

Return values
T

getItem()

Returns a Cache Item representing the specified key.

public getItem(mixed $key) : CacheItemInterface

This method must always return a CacheItemInterface object, even in case of a cache miss. It MUST NOT return null.

Parameters
$key : mixed

The key for which to return the corresponding Cache Item.

Return values
CacheItemInterface

The corresponding Cache Item.

getItems()

Returns a traversable set of cache items.

public getItems([array<string|int, mixed> $keys = [] ]) : iterable<string, CacheItem>
Parameters
$keys : array<string|int, mixed> = []

An indexed array of keys of items to retrieve.

Return values
iterable<string, CacheItem>

getValues()

Returns all cached values, with cache miss as null.

public getValues() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasItem()

Confirms if the cache contains specified cache item.

public hasItem(mixed $key) : bool

Note: This method MAY avoid retrieving the cached value for performance reasons. This could result in a race condition with CacheItemInterface::get(). To avoid such situation use CacheItemInterface::isHit() instead.

Parameters
$key : mixed

The key for which to check existence.

Return values
bool

True if item exists in the cache, false otherwise.

save()

Persists a cache item immediately.

public save(CacheItemInterface $item) : bool
Parameters
$item : CacheItemInterface

The cache item to save.

Return values
bool

True if the item was successfully persisted. False if there was an error.

saveDeferred()

Sets a cache item to be persisted later.

public saveDeferred(CacheItemInterface $item) : bool
Parameters
$item : CacheItemInterface

The cache item to save.

Return values
bool

False if the item could not be queued or if a commit was attempted and failed. True otherwise.

freeze()

private freeze(mixed $value, string $key) : string|int|float|bool|array<string|int, mixed>|UnitEnum|null
Parameters
$value : mixed
$key : string
Return values
string|int|float|bool|array<string|int, mixed>|UnitEnum|null

generateItems()

private generateItems(array<string|int, mixed> $keys, float $now, Closure $f) : Generator
Parameters
$keys : array<string|int, mixed>
$now : float
$f : Closure
Return values
Generator

unfreeze()

private unfreeze(string $key, bool &$isHit) : mixed
Parameters
$key : string
$isHit : bool

validateKeys()

private validateKeys(array<string|int, mixed> $keys) : bool
Parameters
$keys : array<string|int, mixed>
Return values
bool

        
On this page

Search results