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