Drupal Cache

Caching considerations for Drupal with Acquia

Layered approach to caching.

City of Boston use Acquia to host all non local (docker) servers on our deployment workflow.

Varnish

Acquia's servers are contained within an Acquia Cloud subscription and implement a Varnish cache outside the load-balancer, as described here.

Drupal Core Cache

The release of Drupal 8 contains a rebuilt cache strategy using "Tags". Drupal 7's cache expired items based on a lifetime for that item. Drupal 8 introduces another option called cache invalidation. This is where you set the cache lifetime to be permanent and invalidate (purge) that cached item when its no longer relevant. Drupal 8 does this by storing metadata about the cached item. Then, when an event occurs, such as an update on a node, the metadata can be searched to find all cache items that contain computed data about the updated node, and can be invalidated.

Memcache

Memcache (for the purposes of this summary document) can be considered to be a low-level cache which optimizes caching by saving more dynamic process responses to memory. The principal value is to minimize requests between the Drupal kernel and MySQL for queries that are run multiple times during bootstrap and page requests.

Memcache is not used on boston.gov (at this time).

Discover cache activity.

You can inspect the headers of requests to a webserver to see if varnish is enabled, and if content was served from the Varnish and/or Drupal caches.

This terminal command will return the headers from a request to a URL:

curl -IXGET <URL>

Examples:

# Production website.
curl -IXGET http://www.boston.gov

# Acquia cloud development environment.
curl -IXGET http://d8-dev.boston.gov

# Local website (if entered on your local development machine).
curl -IXGET http://boston.lndo.site

Cache layer highlights by layer.

  • Is "passive" caching: Varnish is not aware of the origin of html content it serves/caches.

  • Is outside of the Acquia load-balancers and is the first cache a user request hits.

  • Does not cache content for authenticated users.

  • Is fully independent from the Drupal kernel, and therefore is decoupled from Drupal -except for a purge module provided by Acquia which manipulates a Varnish API. - https://docs.acquia.com/resource/caching/purge/ (Beware: notes are for Drupal 7) - https://www.drupal.org/project/acquia_purge

  • Drupal documentation says in Acquia Cloud, pages are cached for 2 minutes by default.

  • Varnish will accept caching instruction from a web-page headers, so we use Advanced Page Expiry (APE) in drupal to send specific cache instructions to Varnish. The default caching time (set by APE) for CoB drupal pages is 4 weeks (i.e. overrides default 2minutes with 4 weeks!).

  • On boston.gov, the Acquia Purge module is configured to remove entities (pages) from the Varnish cache as they are updated by content editors in Drupal. This invalidation process uses queues in Drupal. The Drupal queue processor is triggered by cron and runs until the queue is exhausted.

On production cron runs every 5 minutes, so (if there is no active queue) it could take up to 5 minutes for content changes to appear.

Onstageanddevelopcron runs every 15 minutes.

The Varnish cache performs 2 functions, one intended and one somewhat unintended.

  1. Reduces load on the application server (i.e. webserver), but also

  2. The cache will continue to serve cached pages even if the application server (webserver) is down or otherwise unavailable. Any cached pages in varnish will continue to be served until the pages expire in the cache. Note: Not all pages are cached, and authenticated sessions are not cached.

Last updated