class MemoryCacheItemPool implements CacheItemPoolInterface (View source)

Simple in-memory cache implementation.

Methods

CacheItemInterface
getItem(string $key)

Returns a Cache Item representing the specified key.

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

Returns a traversable set of cache items.

bool
hasItem(string $key)

Confirms if the cache contains specified cache item.

bool
clear()

Deletes all items in the pool.

bool
deleteItem(string $key)

Removes the item from the pool.

bool
deleteItems(array $keys)

Removes multiple items from the pool.

bool
save(CacheItemInterface $item)

Persists a cache item immediately.

bool
saveDeferred(CacheItemInterface $item)

Sets a cache item to be persisted later.

bool
commit()

Persists any deferred cache items.

Details

CacheItemInterface getItem(string $key)

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.

Return Value

CacheItemInterface The corresponding Cache Item.

Exceptions

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

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

Returns a traversable set of cache items.

Parameters

array $keys An indexed array of keys of items to retrieve.

Return Value

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.

Exceptions

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

bool hasItem(string $key)

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.

Return Value

bool True if item exists in the cache, false otherwise.

Exceptions

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

bool clear()

Deletes all items in the pool.

Return Value

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

bool deleteItem(string $key)

Removes the item from the pool.

Parameters

string $key The key to delete.

Return Value

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

Exceptions

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

bool deleteItems(array $keys)

Removes multiple items from the pool.

Parameters

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

Return Value

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

Exceptions

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

bool save(CacheItemInterface $item)

Persists a cache item immediately.

Parameters

CacheItemInterface $item The cache item to save.

Return Value

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

bool saveDeferred(CacheItemInterface $item)

Sets a cache item to be persisted later.

Parameters

CacheItemInterface $item The cache item to save.

Return Value

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

bool commit()

Persists any deferred cache items.

Return Value

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