How Drupal's chained fast backend keeps APCu cache consistent across your web servers
Drupal's cache.backend.chainedfast makes your site faster without any configuration. All you need is to have APCu on your server. It shows up in the bootstrap, config, and discovery cache bins, and most developers never think about it or even know it is being leveraged.
The chained-fast backend combines two backends: a fast, inconsistent backend (APCu, local to each web server process) and a consistent backend (the database, which is shared across all servers). APCu alone is dangerous in a multi-server environment because each server has its own copy of the data; invalidations on one server don't propagate to others. The chained backend solves this with a last-write timestamp.
Every write to a chained bin records a timestamp in the consistent backend and writes data to both backends. On a read, ChainedFastBackend checks APCu first, but before returning the cached item, it compares the item's creation timestamp against the stored last-write timestamp. If the item was written before the last write timestamp, it's considered stale and discarded. The backend then falls back to the database, fetches the current item, and populates APCu to keep future reads fast.
This design has one significant consequence: every write to a chained bin invalidates all other items in that bin. When the write timestamp advances, anything in APCu with an older timestamp becomes stale on the next read. That's why Drupal restricts the chained fast backend to bins like bootstrap, config, and discovery, which have infrequent writes and very frequent reads. Using it on a high-write bin would cause constant APCu cache misses, negating any performance benefit.
The write path is direct: data is sent to APCu and the database simultaneously, and the last-write timestamp is updated. If APCu is unavailable, ChainedFastBackendFactory returns only the consistent database backend with no chaining at all; zero configuration required. This is covered in depth, along with BackendChain, custom bin definitions, and the full render cache pipeline, in Understanding Drupal: The Complete Guide to Caching Layers.
📘 Understanding Drupal: A Complete Guide to Caching Layers — my new book is out now!
Want more? Sign up for my weekly newsletter