Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

12
Caching Strategies for Scaling Drupal Common Missteps vs Best Practices Corey Wood Senior Technical Account Manager

Transcript of Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

Page 1: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

Caching Strategies for Scaling DrupalCommon Missteps vs Best Practices

Corey WoodSenior Technical Account Manager

Page 2: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

Who?Corey WoodSenior 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

Page 3: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

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

Page 4: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

Never do the same work twice

Page 5: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

The Importance of Proper CachingThe 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?

Page 6: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

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

Page 7: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

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

Page 8: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

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

Page 9: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

Moving Cache Outside of DrupalMemcache

→ 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

Page 10: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

There are only two hard things in Computer Science: cache invalidation and naming things.

Page 11: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

Invalidating, Purging, and WarmingInvalidating 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

Page 12: Caching Strategies for Scaling Drupal: Common Missteps vs Best Practices

Thank You