class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface

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.

Traits

An implementation of CacheInterface for PSR-6 CacheItemPoolInterface classes.

Methods

prune()

{@inheritdoc}

reset()

{@inheritdoc}

warmUp(array $values)

Store an array of cached values.

clear()

{@inheritdoc}

mixed
get(string $key, callable $callback, float $beta = null, array $metadata = null)

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

bool
delete(string $key)

{@inheritdoc}

callable
setCallbackWrapper(callable|null $callbackWrapper)

Wraps the callback passed to ->get() in a callable.

__construct(string $file, AdapterInterface $fallbackPool)

No description

static CacheItemPoolInterface
create(string $file, CacheItemPoolInterface $fallbackPool)

This adapter takes advantage of how PHP stores arrays in its latest versions.

getItem($key)

{@inheritdoc}

getItems(array $keys = [])

{@inheritdoc}

hasItem($key)

{@inheritdoc}

deleteItem($key)

{@inheritdoc}

deleteItems(array $keys)

{@inheritdoc}

save(CacheItemInterface $item)

{@inheritdoc}

saveDeferred(CacheItemInterface $item)

{@inheritdoc}

commit()

{@inheritdoc}

static 
throwOnRequiredClass($class)

No description

Details

in ProxyTrait at line 29
prune()

{@inheritdoc}

in ProxyTrait at line 37
reset()

{@inheritdoc}

in PhpArrayTrait at line 37
warmUp(array $values)

Store an array of cached values.

Parameters

array $values The cached values

in PhpArrayTrait at line 125
clear()

{@inheritdoc}

at line 85
mixed get(string $key, callable $callback, float $beta = null, array $metadata = null)

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

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

string $key The key of the item to retrieve from the cache
callable $callback Should return the computed value for the given key/item
float $beta 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
array $metadata &$metadata The metadata of the cached item {see ItemInterface::getMetadata()}

Return Value

mixed The value corresponding to the provided key

Exceptions

InvalidArgumentException When $key is not valid or when $beta is negative

in CacheTrait at line 35
bool delete(string $key)

{@inheritdoc}

Parameters

string $key

Return Value

bool

in ContractsTrait at line 40
callable setCallbackWrapper(callable|null $callbackWrapper)

Wraps the callback passed to ->get() in a callable.

Parameters

callable|null $callbackWrapper

Return Value

callable the previous callback wrapper

at line 42
__construct(string $file, AdapterInterface $fallbackPool)

Parameters

string $file The PHP file were values are cached
AdapterInterface $fallbackPool A pool to fallback on when an item is not hit

at line 68
static CacheItemPoolInterface create(string $file, CacheItemPoolInterface $fallbackPool)

This adapter takes advantage of how PHP stores arrays in its latest versions.

Parameters

string $file The PHP file were values are cached
CacheItemPoolInterface $fallbackPool Fallback when opcache is disabled

Return Value

CacheItemPoolInterface

at line 118
CacheItem getItem($key)

{@inheritdoc}

Parameters

$key

Return Value

CacheItem

at line 152
Traversable|CacheItem[] getItems(array $keys = [])

{@inheritdoc}

Parameters

array $keys

Return Value

Traversable|CacheItem[]

at line 169
hasItem($key)

{@inheritdoc}

Parameters

$key

at line 184
deleteItem($key)

{@inheritdoc}

Parameters

$key

at line 199
deleteItems(array $keys)

{@inheritdoc}

Parameters

array $keys

at line 229
save(CacheItemInterface $item)

{@inheritdoc}

Parameters

CacheItemInterface $item

at line 241
saveDeferred(CacheItemInterface $item)

{@inheritdoc}

Parameters

CacheItemInterface $item

at line 253
commit()

{@inheritdoc}

at line 293
static throwOnRequiredClass($class)

Parameters

$class

Exceptions

ReflectionException When $class is not found and is required