BackendChain
class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterface (View source)
Defines a chained cache implementation for combining multiple cache backends.
Can be used to combine two or more backends together to behave as if they were a single backend.
For example a slower, persistent storage engine could be combined with a faster, volatile storage engine. When retrieving items from cache, they will be fetched from the volatile backend first, only falling back to the persistent backend if an item is not available. An item not present in the volatile backend but found in the persistent one will be propagated back up to ensure fast retrieval on the next request. On cache sets and deletes, both backends will be invoked to ensure consistency.
Properties
| protected array | $backends | Ordered list of CacheBackendInterface instances. |
Methods
Returns data from the persistent cache.
Returns data from the persistent cache when given an array of cache IDs.
Stores data in the persistent cache.
Store multiple items in the persistent cache.
Deletes an item from the cache.
Deletes multiple items from the cache.
Deletes all cache items in a bin.
Marks a cache item as invalid.
Marks cache items as invalid.
Marks cache items with any of the specified tags as invalid.
Marks all cache items as invalid.
Performs garbage collection on a cache bin.
Remove a cache bin.
Details
$this
appendBackend(CacheBackendInterface $backend)
Appends a cache backend to the cache chain.
$this
prependBackend(CacheBackendInterface $backend)
Prepends a cache backend to the cache chain.
object|false
get(string $cid, bool $allow_invalid = FALSE)
Returns data from the persistent cache.
array
getMultiple(array $cids, bool $allow_invalid = FALSE)
Returns data from the persistent cache when given an array of cache IDs.
set(string $cid, mixed $data, int $expire = Cache::PERMANENT, array $tags = [])
Stores data in the persistent cache.
Core cache implementations set the created time on cache item with microtime(TRUE) rather than REQUEST_TIME_FLOAT, because the created time of cache items should match when they are created, not when the request started. Apart from being more accurate, this increases the chance an item will legitimately be considered valid.
setMultiple(array $items)
Store multiple items in the persistent cache.
delete(string $cid)
Deletes an item from the cache.
If the cache item is being deleted because it is no longer "fresh", you may consider using invalidate() instead. This allows callers to retrieve the invalid item by calling get() with $allow_invalid set to TRUE. In some cases an invalid item may be acceptable rather than having to rebuild the cache.
deleteMultiple(array $cids)
Deletes multiple items from the cache.
If the cache items are being deleted because they are no longer "fresh", you may consider using invalidateMultiple() instead. This allows callers to retrieve the invalid items by calling get() with $allow_invalid set to TRUE. In some cases an invalid item may be acceptable rather than having to rebuild the cache.
deleteAll()
Deletes all cache items in a bin.
invalidate(string $cid)
Marks a cache item as invalid.
Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.
invalidateMultiple(array $cids)
Marks cache items as invalid.
Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.
invalidateTags(array $tags)
Marks cache items with any of the specified tags as invalid.
invalidateAll()
Marks all cache items as invalid.
Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.
garbageCollection()
Performs garbage collection on a cache bin.
The backend may choose to delete expired or invalidated items.
removeBin()
Remove a cache bin.