PhpArrayAdapter
in package
implements
AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
Uses
ContractsTrait, ProxyTrait
Caches items at warm up time using a PHP array that is stored in shared memory by OPCache since PHP 7.0.
Warmed up items are read-only and run-time discovered items are cached using a fallback adapter.
Tags
Table of Contents
Interfaces
- AdapterInterface
- Interface for adapters managing instances of Symfony's CacheItem.
- CacheInterface
- Covers most simple to advanced caching needs.
- PruneableInterface
- Interface extends psr-6 and psr-16 caches to allow for pruning (deletion) of all expired cache items.
- ResettableInterface
- Resets a pool's local state.
Properties
- $createCacheItem : Closure
- $file : string
- $keys : array<string|int, mixed>
- $values : array<string|int, mixed>
- $valuesCache : array<string|int, mixed>
Methods
- __construct() : mixed
- clear() : bool
- Deletes all items in the pool.
- commit() : bool
- {@inheritdoc}
- create() : CacheItemPoolInterface
- This adapter takes advantage of how PHP stores arrays in its latest versions.
- 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.
- hasItem() : bool
- {@inheritdoc}
- save() : bool
- {@inheritdoc}
- saveDeferred() : bool
- {@inheritdoc}
- warmUp() : array<string|int, string>
- Store an array of cached values.
- generateItems() : Generator
- initialize() : mixed
- Load the cache file.
Properties
$createCacheItem
private
static Closure
$createCacheItem
$file
private
string
$file
$keys
private
array<string|int, mixed>
$keys
$values
private
array<string|int, mixed>
$values
$valuesCache
private
static array<string|int, mixed>
$valuesCache
= []
Methods
__construct()
public
__construct(string $file, AdapterInterface $fallbackPool) : mixed
Parameters
- $file : string
-
The PHP file were values are cached
- $fallbackPool : AdapterInterface
-
A pool to fallback on when an item is not hit
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
boolcreate()
This adapter takes advantage of how PHP stores arrays in its latest versions.
public
static create(string $file, CacheItemPoolInterface $fallbackPool) : CacheItemPoolInterface
Parameters
- $file : string
-
The PHP file were values are cached
- $fallbackPool : CacheItemPoolInterface
-
A pool to fallback on when an item is not hit
Return values
CacheItemPoolInterfacedeleteItem()
{@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>hasItem()
{@inheritdoc}
public
hasItem(mixed $key) : bool
Parameters
- $key : mixed
Return values
boolsave()
{@inheritdoc}
public
save(CacheItemInterface $item) : bool
Parameters
- $item : CacheItemInterface
Return values
boolsaveDeferred()
{@inheritdoc}
public
saveDeferred(CacheItemInterface $item) : bool
Parameters
- $item : CacheItemInterface
Return values
boolwarmUp()
Store an array of cached values.
public
warmUp(array<string|int, mixed> $values) : array<string|int, string>
Parameters
- $values : array<string|int, mixed>
-
The cached values
Return values
array<string|int, string> —A list of classes to preload on PHP 7.4+
generateItems()
private
generateItems(array<string|int, mixed> $keys) : Generator
Parameters
- $keys : array<string|int, mixed>
Return values
Generatorinitialize()
Load the cache file.
private
initialize() : mixed