Leanpub Header

Skip to main content

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.00

Author earns

$20.00
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
WEB
About

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.

Share this book

Categories

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

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

  1. Why I wrote this book
  2. Who is this book for?
  3. What to expect
  4. Do you need a Drupal site for this book?

Introduction

  1. Why does caching matter?

Cacheable metadata: tags, contexts, and max age

  1. What are render arrays?
  2. What is cache invalidation
  3. What is cacheable metadata?
  4. Cacheable dependencies
  5. Cache tags
  6. Cache contexts
  7. Cache tags vs. cache contexts
  8. Cache max-age (time-to-live)
  9. Bubbleable rendering metadata

Cache items, their backends, and stores

  1. Retrieving, storing, and deleting cache items
  2. Available cache backend stores
  3. Defining a custom cache bin
  4. Defining cache bins with chained backend stores
  5. Changing a cache bin’s backend store
  6. Disabling a cache bin for development
  7. Managing cache with Drush

Render (fragment) cache

  1. Rendering in Drupal
  2. Discovery and compilation caches
  3. Specifying render cache keys
  4. Bubbling metadata
  5. Placeholders for late rendering
  6. Caching non-markup data alongside rendered markup

Caching responses

  1. Cacheable response objects
  2. Access checks and response cacheability
  3. Dynamic page cache
  4. Internal page cache
  5. When to use Dynamic Page Cache vs Internal Page Cache
  6. Caching 4xx responses
  7. Streaming responses with BigPipe

HTTP caching headers

  1. How Drupal determines cacheability
  2. Working with cacheable responses
  3. Important limitations and gotchas
  4. The Vary header
  5. The Cache-Control header
  6. The Expires header
  7. The Last-Modified header
  8. The ETag header
  9. The Surrogate-Control header
  10. Extending HTTP cache headers with the HTTP Cache Control module

Reverse proxies and CDNs

  1. What are reverse proxies and CDNs?
  2. Making Drupal aware it is behind a reverse proxy or CDN
  3. Exposing cache tags through HTTP headers
  4. The Purge module
  5. Varnish reverse proxy
  6. Nginx as a reverse proxy
  7. Bypassing the cache for authenticated requests
  8. Content Delivery Networks (CDNs)
  9. Edge Side Includes

Debugging your cache

  1. Turning on development mode to bypass Twig and markup caching
  2. Disabling specific render and response caches during development
  3. Debug response cacheable metadata with HTTP response headers
  4. Inspecting cache headers in the browser
  5. Render debug output for cacheable metadata
  6. Reviewing the cache bins and cache IDs
  7. Inspecting caches with Drush
  8. Visualization modules

Writing code with cacheability in mind

  1. Using the “list” cache tag when listing entities
  2. Cacheable responses
  3. Working with cache contexts
  4. Caching forms
  5. Cacheable objects as dependencies
  6. Traits for implementing cacheable dependency interfaces
  7. Capturing correct metadata
  8. Capturing leaked metadata when rendering
  9. Implementing lazy builders
  10. Preloading cache tags for checksum optimization
  11. Prewarming caches to prevent stampedes
  12. Forcing uncacheable content with CacheOptionalInterface
  13. The Variation Cache API
  14. Testing cache metadata

Afterword

  1. What You’ve Learned
  2. Where to Go Next
  3. Staying Connected
  4. 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.

Learn more about writing on Leanpub