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 = array())

{@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

prune()

{@inheritdoc}

reset()

{@inheritdoc}

warmUp(array $values)

Store an array of cached values.

Parameters

array $values The 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.

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

bool delete(string $key)

{@inheritdoc}

Parameters

string $key

Return Value

bool

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

__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

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

CacheItem getItem($key)

{@inheritdoc}

Parameters

$key

Return Value

CacheItem

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

{@inheritdoc}

Parameters

array $keys

Return Value

Traversable|CacheItem[]

hasItem($key)

{@inheritdoc}

Parameters

$key

deleteItem($key)

{@inheritdoc}

Parameters

$key

deleteItems(array $keys)

{@inheritdoc}

Parameters

array $keys

save(CacheItemInterface $item)

{@inheritdoc}

Parameters

CacheItemInterface $item

saveDeferred(CacheItemInterface $item)

{@inheritdoc}

Parameters

CacheItemInterface $item

commit()

{@inheritdoc}

static throwOnRequiredClass($class)

Parameters

$class

Exceptions

ReflectionException When $class is not found and is required