class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface

Chains several adapters together.

Cached items are fetched from the first adapter having them in its data store. They are saved and deleted in all adapters at once.

Traits

An implementation of CacheInterface for PSR-6 CacheItemPoolInterface classes.

Methods

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(array $adapters, int $defaultLifetime = 0)

No description

getItem($key)

{@inheritdoc}

getItems(array $keys = array())

{@inheritdoc}

hasItem($key)

{@inheritdoc}

clear()

{@inheritdoc}

deleteItem($key)

{@inheritdoc}

deleteItems(array $keys)

{@inheritdoc}

save(CacheItemInterface $item)

{@inheritdoc}

saveDeferred(CacheItemInterface $item)

{@inheritdoc}

commit()

{@inheritdoc}

bool
prune()

No description

reset()

No description

Details

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(array $adapters, int $defaultLifetime = 0)

Parameters

array $adapters The ordered list of adapters used to fetch cached items
int $defaultLifetime The default lifetime of items propagated from lower adapters to upper ones

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

clear()

{@inheritdoc}

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}

bool prune()

Return Value

bool

reset()