Defines a backend with a fast and a consistent backend chain.
In order to mitigate a network roundtrip for each cache get operation, this cache allows a fast backend to be put in front of a slow(er) backend. Typically the fast backend will be something like APCu, and be bound to a single web node, and will not require a network round trip to fetch a cache item. The fast backend will also typically be inconsistent (will only see changes from one web node). The slower backend will be something like Mysql, Memcached or Redis, and will be used by all web nodes, thus making it consistent, but also require a network round trip for each cache get.
In addition to being useful for sites running on multiple web nodes, this backend can also be useful for sites running on a single web node where the fast backend (e.g., APCu) isn't shareable between the web and CLI processes. Single-node configurations that don't have that limitation can just use the fast cache backend directly.
We always use the fast backend when reading (get()) entries from cache, but check whether they were created before the last write (set()) to this (chained) cache backend. Those cache entries that were created before the last write are discarded, but we use their cache IDs to then read them from the consistent (slower) cache backend instead; at the same time we update the fast cache backend so that the next read will hit the faster backend again. Hence we can guarantee that the cache entries we return are all up-to-date, and maximally exploit the faster cache backend. This cache backend uses and maintains a "last write timestamp" to determine which cache entries should be discarded.
Because this backend will mark all the cache entries in a bin as out-dated for each write to a bin, it is best suited to bins with fewer changes.
Note that this is designed specifically for combining a fast inconsistent cache backend with a slower consistent cache back-end. To still function correctly, it needs to do a consistency check (see the "last write timestamp" logic). This contrasts with \Drupal\Core\Cache\BackendChain, which assumes both chained cache backends are consistent, thus a consistency check being pointless.
Hierarchy
- class \Drupal\Core\Cache\ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorInterface
See also
\Drupal\Core\Cache\BackendChain
Related topics
- Cache API
- Information about the Drupal Cache API
File
- core/lib/Drupal/Core/Cache/ChainedFastBackend.php, line 48
Namespace
Drupal\Core\Cache
Members
Name | Modifiers | Type | Description |
---|---|---|---|
CacheBackendInterface::CACHE_PERMANENT | constant | Indicates that the item should never be removed unless explicitly deleted. | |
ChainedFastBackend::$bin | protected | property | |
ChainedFastBackend::$consistentBackend | protected | property | The consistent cache backend. |
ChainedFastBackend::$fastBackend | protected | property | The fast cache backend. |
ChainedFastBackend::$lastWriteTimestamp | protected | property | The time at which the last write to this cache bin happened. |
ChainedFastBackend::delete | public | function | Deletes an item from the cache. Overrides CacheBackendInterface::delete |
ChainedFastBackend::deleteAll | public | function | Deletes all cache items in a bin. Overrides CacheBackendInterface::deleteAll |
ChainedFastBackend::deleteMultiple | public | function | Deletes multiple items from the cache. Overrides CacheBackendInterface::deleteMultiple |
ChainedFastBackend::garbageCollection | public | function | Performs garbage collection on a cache bin. Overrides CacheBackendInterface::garbageCollection |
ChainedFastBackend::get | public | function | Returns data from the persistent cache. Overrides CacheBackendInterface::get |
ChainedFastBackend::getLastWriteTimestamp | protected | function | Gets the last write timestamp. |
ChainedFastBackend::getMultiple | public | function | Returns data from the persistent cache when given an array of cache IDs. Overrides CacheBackendInterface::getMultiple |
ChainedFastBackend::invalidate | public | function | Marks a cache item as invalid. Overrides CacheBackendInterface::invalidate |
ChainedFastBackend::invalidateAll | public | function | Marks all cache items as invalid. Overrides CacheBackendInterface::invalidateAll |
ChainedFastBackend::invalidateMultiple | public | function | Marks cache items as invalid. Overrides CacheBackendInterface::invalidateMultiple |
ChainedFastBackend::invalidateTags | public | function | Marks cache items with any of the specified tags as invalid. Overrides CacheTagsInvalidatorInterface::invalidateTags |
ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX | constant | Cache key prefix for the bin-specific entry to track the last write. | |
ChainedFastBackend::markAsOutdated | protected | function | Marks the fast cache bin as outdated because of a write. |
ChainedFastBackend::removeBin | public | function | Remove a cache bin. Overrides CacheBackendInterface::removeBin |
ChainedFastBackend::reset | public | function | @todo Document in https://www.drupal.org/node/2311945. |
ChainedFastBackend::set | public | function | Stores data in the persistent cache. Overrides CacheBackendInterface::set |
ChainedFastBackend::setMultiple | public | function | Store multiple items in the persistent cache. Overrides CacheBackendInterface::setMultiple |
ChainedFastBackend::__construct | public | function | Constructs a ChainedFastBackend object. |
Please login to continue.