Understanding Drupal: A Complete Guide to Caching Layers
Drupal's caching system is powerful only when you understand how its layers connect. This book walks you through cacheable metadata, render caching, HTTP headers, and reverse proxy configuration; the complete stack from page assembly to CDN edge.
Minimum price
$10.00
$25.00
You pay
$25.00Author earns
$20.00Buying multiple copies for your team? See below for a discount!
About
About the Book
Drupal's caching architecture spans multiple layers: render arrays in memory, cache backends in the database, HTTP headers on the response, and rules in the reverse proxy. Getting any layer wrong costs you either performance or correctness.
This book covers the full stack. You will learn how cacheable metadata flows through the render pipeline, how cache backends store and invalidate data, how HTTP response headers instruct reverse proxies, and how to write modules that participate correctly at every layer. Chapters progress from core concepts to debugging real-world cache failures and writing cacheable code from scratch.
The audience ranges from site builders who want to understand cache tags to module developers building custom cache backends. Every chapter works through real Drupal 11 APIs, grounded in code.
Team Discounts
Team Discounts
Get a team discount on this book!
Up to 3 members
- Minimum price
- $25.00
- Suggested price
- $62.00
Up to 5 members
- Minimum price
- $40.00
- Suggested price
- $100.00
Up to 10 members
- Minimum price
- $70.00
- Suggested price
- $175.00
Up to 15 members
- Minimum price
- $100.00
- Suggested price
- $250.00
Up to 25 members
- Minimum price
- $150.00
- Suggested price
- $375.00
Author
About the Author
Matt Glaman is a Principal Software Engineer at Acquia, specializing in Drupal and PHP. He's an active contributor to the Drupal open source ecosystem, focusing on developer tooling, caching architecture, and modern PHP practices. Matt writes at mglaman.dev and is a strong advocate of static analysis, clean APIs, and code that ships value rather than impresses.
Contents
Table of Contents
Preface
- Why I wrote this book
- Who is this book for?
- What to expect
- Do you need a Drupal site for this book?
Introduction
- Why does caching matter?
Cacheable metadata: tags, contexts, and max age
- What are render arrays?
- What is cache invalidation
- What is cacheable metadata?
- Cacheable dependencies
- Cache tags
- Cache contexts
- Cache tags vs. cache contexts
- Cache max-age (time-to-live)
- Bubbleable rendering metadata
Cache items, their backends, and stores
- Retrieving, storing, and deleting cache items
- Available cache backend stores
- Defining a custom cache bin
- Defining cache bins with chained backend stores
- Changing a cache bin’s backend store
- Disabling a cache bin for development
- Managing cache with Drush
Render (fragment) cache
- Rendering in Drupal
- Discovery and compilation caches
- Specifying render cache keys
- Bubbling metadata
- Placeholders for late rendering
- Caching non-markup data alongside rendered markup
Caching responses
- Cacheable response objects
- Access checks and response cacheability
- Dynamic page cache
- Internal page cache
- When to use Dynamic Page Cache vs Internal Page Cache
- Caching 4xx responses
- Streaming responses with BigPipe
HTTP caching headers
- How Drupal determines cacheability
- Working with cacheable responses
- Important limitations and gotchas
- The
Varyheader - The
Cache-Controlheader - The
Expiresheader - The
Last-Modifiedheader - The
ETagheader - The
Surrogate-Controlheader - Extending HTTP cache headers with the HTTP Cache Control module
Reverse proxies and CDNs
- What are reverse proxies and CDNs?
- Making Drupal aware it is behind a reverse proxy or CDN
- Exposing cache tags through HTTP headers
- The Purge module
- Varnish reverse proxy
- Nginx as a reverse proxy
- Bypassing the cache for authenticated requests
- Content Delivery Networks (CDNs)
- Edge Side Includes
Debugging your cache
- Turning on development mode to bypass Twig and markup caching
- Disabling specific render and response caches during development
- Debug response cacheable metadata with HTTP response headers
- Inspecting cache headers in the browser
- Render debug output for cacheable metadata
- Reviewing the cache bins and cache IDs
- Inspecting caches with Drush
- Visualization modules
Writing code with cacheability in mind
- Using the “list” cache tag when listing entities
- Cacheable responses
- Working with cache contexts
- Caching forms
- Cacheable objects as dependencies
- Traits for implementing cacheable dependency interfaces
- Capturing correct metadata
- Capturing leaked metadata when rendering
- Implementing lazy builders
- Preloading cache tags for checksum optimization
- Prewarming caches to prevent stampedes
- Forcing uncacheable content with CacheOptionalInterface
- The Variation Cache API
- Testing cache metadata
Afterword
- What You’ve Learned
- Where to Go Next
- Staying Connected
- Thank You
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.