\Psr\CacheCacheItemPoolInterface

CacheItemPoolInterface generates CacheItemInterface objects.

The primary purpose of Cache\CacheItemPoolInterface is to accept a key from the Calling Library and return the associated Cache\CacheItemInterface object. It is also the primary point of interaction with the entire cache collection. All configuration and initialization of the Pool is left up to an Implementing Library.

Summary

Methods
Constants
getItem()
getItems()
hasItem()
clear()
deleteItem()
deleteItems()
save()
saveDeferred()
commit()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

getItem()

getItem(string  $key) : \Psr\Cache\CacheItemInterface

Returns a Cache Item representing the specified key.

This method must always return a CacheItemInterface object, even in case of a cache miss. It MUST NOT return null.

Parameters

string $key

The key for which to return the corresponding Cache Item.

Throws

\Psr\Cache\InvalidArgumentException

If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException MUST be thrown.

Returns

\Psr\Cache\CacheItemInterface

The corresponding Cache Item.

getItems()

getItems(array<mixed,string>  $keys = array()) : array|\Traversable

Returns a traversable set of cache items.

Parameters

array<mixed,string> $keys

An indexed array of keys of items to retrieve.

Throws

\Psr\Cache\InvalidArgumentException

If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException MUST be thrown.

Returns

array|\Traversable —

A traversable collection of Cache Items keyed by the cache keys of each item. A Cache item will be returned for each key, even if that key is not found. However, if no keys are specified then an empty traversable MUST be returned instead.

hasItem()

hasItem(string  $key) : boolean

Confirms if the cache contains specified cache item.

Note: This method MAY avoid retrieving the cached value for performance reasons. This could result in a race condition with CacheItemInterface::get(). To avoid such situation use CacheItemInterface::isHit() instead.

Parameters

string $key

The key for which to check existence.

Throws

\Psr\Cache\InvalidArgumentException

If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException MUST be thrown.

Returns

boolean —

True if item exists in the cache, false otherwise.

clear()

clear() : boolean

Deletes all items in the pool.

Returns

boolean —

True if the pool was successfully cleared. False if there was an error.

deleteItem()

deleteItem(string  $key) : boolean

Removes the item from the pool.

Parameters

string $key

The key to delete.

Throws

\Psr\Cache\InvalidArgumentException

If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException MUST be thrown.

Returns

boolean —

True if the item was successfully removed. False if there was an error.

deleteItems()

deleteItems(array<mixed,string>  $keys) : boolean

Removes multiple items from the pool.

Parameters

array<mixed,string> $keys

An array of keys that should be removed from the pool.

Throws

\Psr\Cache\InvalidArgumentException

If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException MUST be thrown.

Returns

boolean —

True if the items were successfully removed. False if there was an error.

save()

save(\Psr\Cache\CacheItemInterface  $item) : boolean

Persists a cache item immediately.

Parameters

\Psr\Cache\CacheItemInterface $item

The cache item to save.

Returns

boolean —

True if the item was successfully persisted. False if there was an error.

saveDeferred()

saveDeferred(\Psr\Cache\CacheItemInterface  $item) : boolean

Sets a cache item to be persisted later.

Parameters

\Psr\Cache\CacheItemInterface $item

The cache item to save.

Returns

boolean —

False if the item could not be queued or if a commit was attempted and failed. True otherwise.

commit()

commit() : boolean

Persists any deferred cache items.

Returns

boolean —

True if all not-yet-saved items were successfully saved or there were none. False otherwise.