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
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
- $values : array<string|int, mixed>
Methods
- __construct() : mixed
- clear() : bool
- Deletes all items in the pool.
- commit() : bool
- {@inheritdoc}
- delete() : bool
- Removes an item from the pool.
- deleteItem() : bool
- {@inheritdoc}
- deleteItems() : bool
- {@inheritdoc}
- get() : mixed
- 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
- {@inheritdoc}
- reset() : mixed
- {@inheritdoc}
- save() : bool
- {@inheritdoc}
- saveDeferred() : bool
- {@inheritdoc}
- setLogger() : void
- Sets a logger.
- freeze() : mixed
- generateItems() : Generator
- unfreeze() : mixed
- validateKeys() : bool
Properties
$logger
The logger instance.
protected
LoggerInterface|null
$logger
= null
$createCacheItem
private
static Closure
$createCacheItem
$defaultLifetime
private
int
$defaultLifetime
$expiries
private
array<string|int, mixed>
$expiries
= []
$maxItems
private
int
$maxItems
$maxLifetime
private
float
$maxLifetime
$storeSerialized
private
bool
$storeSerialized
$values
private
array<string|int, mixed>
$values
= []
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()
{@inheritdoc}
public
commit() : bool
Return values
booldelete()
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()
{@inheritdoc}
public
deleteItem(mixed $key) : bool
Parameters
- $key : mixed
Return values
booldeleteItems()
{@inheritdoc}
public
deleteItems(array<string|int, mixed> $keys) : bool
Parameters
- $keys : array<string|int, mixed>
Return values
boolget()
Fetches a value from the pool or computes it if not found.
public
get(string $key, callable $callback[, float $beta = null ][, array<string|int, mixed> &$metadata = null ]) : mixed
Parameters
- $key : string
-
The key of the item to retrieve from the cache
- $callback : callable
-
Should return the computed value for the given key/item
- $beta : float = 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
-
The metadata of the cached item ItemInterface::getMetadata()
getItem()
Returns a Cache Item representing the specified key.
public
getItem(mixed $key) : CacheItemInterface
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()
{@inheritdoc}
public
hasItem(mixed $key) : bool
Parameters
- $key : mixed
Return values
boolreset()
{@inheritdoc}
public
reset() : mixed
save()
{@inheritdoc}
public
save(CacheItemInterface $item) : bool
Parameters
- $item : CacheItemInterface
Return values
boolsaveDeferred()
{@inheritdoc}
public
saveDeferred(CacheItemInterface $item) : bool
Parameters
- $item : CacheItemInterface
Return values
boolsetLogger()
Sets a logger.
public
setLogger(LoggerInterface $logger) : void
Parameters
- $logger : LoggerInterface
freeze()
private
freeze(mixed $value, string $key) : mixed
Parameters
- $value : mixed
- $key : string
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
Generatorunfreeze()
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>