Caching Strategies for
Scaling Drupal
Common Missteps vs Best Practices
Corey Wood
Senior Technical Account Manager
Who?
Corey Wood
Senior Technical Account Manager, Team Lead
→ Drupalist since 2006 - Drupal 4.7
→ Acquia Certified Developer
→ Certified ScrumMaster
→ Gold medal winning homebrewer
→ Industry Experience:
▪ Publishing
▪ Advertising
▪ Higher Education
▪ Public Sector
▪ Craft Brewing
What?
Caching
→ When, where, why, and how Drupal cache works
→ When, where, why, and how Drupal cache doesn’t work
→ Best practices
▪ Cache invalidation
▪ TTL management
→ Common missteps
▪ Invalidation, purging, and warming
→ D7 and D8 differences
→ Leveraging external proxy cache
Never do the same work twice
The Importance of Proper Caching
The Basics
→ Anatomy of a page request
→ Know your limitations
▪ PHP processes
▪ MySQL connections
▪ CPU usage
→ Never do the same work twice…
▪ ...whenever possible
→ What should we cache, and for how long?
▪ Everything?
▪ Forever?
Caching in Drupal 7
→ “Clear all caches”
→ Cache pages for anonymous users
→ Cache blocks
→ Minimum cache lifetime
→ Expiration of cached pages
→ CSS and JS aggregation
Caching in Drupal 8
→ “Clear all caches”
→ Cache pages for anonymous users
→ Cache blocks
→ Minimum cache lifetime
→ Page cache maximum age
→ CSS and JS aggregation
What’s New in Drupal 8
→ Cache tags
▪ More granular control over cache invalidation
→ Cache Context API
▪ You can now cache more variants based off of a context (url, user, language, cookie,
etc)
→ #post_render_cache
▪ Similar to Edge Side Includes, allows for dynamic elements in cached objects
→ Much more
▪ CSS/JS aggregation on by default
▪ JS loaded from the bottom
▪ Block Cache API removed in favor of render caching
Moving Cache Outside of Drupal
Memcache
→ Move Drupal’s cache from the database to memory
Varnish
→ Add a reverse proxy caching layer in front of your application to handle larger numbers of
requests.
Content Delivery Network
→ An additional layer of distributed reverse proxy cache providing greater scalability and
protection
There are only two hard things in Computer Science: cache invalidation and naming things.
Invalidating, Purging, and Warming
Invalidating cache
→ Minimum cache lifetime in D7
→ Using Rules and the Expire module
Purging cache
→ The contrib Purge module is your friend
→ drush cc all
Warming cache
→ The order in which caches are cleared is very important
→ Drupal -> Proxy
Thank You

Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

  • 1.
    Caching Strategies for ScalingDrupal Common Missteps vs Best Practices Corey Wood Senior Technical Account Manager
  • 2.
    Who? Corey Wood Senior TechnicalAccount Manager, Team Lead → Drupalist since 2006 - Drupal 4.7 → Acquia Certified Developer → Certified ScrumMaster → Gold medal winning homebrewer → Industry Experience: ▪ Publishing ▪ Advertising ▪ Higher Education ▪ Public Sector ▪ Craft Brewing
  • 3.
    What? Caching → When, where,why, and how Drupal cache works → When, where, why, and how Drupal cache doesn’t work → Best practices ▪ Cache invalidation ▪ TTL management → Common missteps ▪ Invalidation, purging, and warming → D7 and D8 differences → Leveraging external proxy cache
  • 4.
    Never do thesame work twice
  • 5.
    The Importance ofProper Caching The Basics → Anatomy of a page request → Know your limitations ▪ PHP processes ▪ MySQL connections ▪ CPU usage → Never do the same work twice… ▪ ...whenever possible → What should we cache, and for how long? ▪ Everything? ▪ Forever?
  • 6.
    Caching in Drupal7 → “Clear all caches” → Cache pages for anonymous users → Cache blocks → Minimum cache lifetime → Expiration of cached pages → CSS and JS aggregation
  • 7.
    Caching in Drupal8 → “Clear all caches” → Cache pages for anonymous users → Cache blocks → Minimum cache lifetime → Page cache maximum age → CSS and JS aggregation
  • 8.
    What’s New inDrupal 8 → Cache tags ▪ More granular control over cache invalidation → Cache Context API ▪ You can now cache more variants based off of a context (url, user, language, cookie, etc) → #post_render_cache ▪ Similar to Edge Side Includes, allows for dynamic elements in cached objects → Much more ▪ CSS/JS aggregation on by default ▪ JS loaded from the bottom ▪ Block Cache API removed in favor of render caching
  • 9.
    Moving Cache Outsideof Drupal Memcache → Move Drupal’s cache from the database to memory Varnish → Add a reverse proxy caching layer in front of your application to handle larger numbers of requests. Content Delivery Network → An additional layer of distributed reverse proxy cache providing greater scalability and protection
  • 10.
    There are onlytwo hard things in Computer Science: cache invalidation and naming things.
  • 11.
    Invalidating, Purging, andWarming Invalidating cache → Minimum cache lifetime in D7 → Using Rules and the Expire module Purging cache → The contrib Purge module is your friend → drush cc all Warming cache → The order in which caches are cleared is very important → Drupal -> Proxy
  • 12.