When you're using Varnish caching in Drupal 7 and 8, you might see headers on an HTTP request that mentions a Varnish
HIT and a Drupal cache
MISS. This result isn't abnormal. Here's how it happens:
- Varnish receives a request. It's a
MISS, so it's passed through to Drupal.
- Drupal receives the request. It's also a
- Drupal caches the page and sends it back to Varnish with a response header indicating that it was a
- Varnish caches the
MISSresponse, which includes the
X-Drupal-Cache: MISSresponse header.
When the page is requested again, it will be a cache
HIT for Varnish, but it will contain the now cached response from Drupal, which has the
X-Drupal-Cache: MISS response header. Every time a request for that page returns a Varnish
HIT, it terminates without hitting Drupal. Because of this, the
X-Drupal-Cache header is not necessarily providing up-to-date information, because it was cached in the past and will remain there until the cache's TTL (Time to Live) (
max-age) has passed.
This pattern of
HIT will occur when Varnish and Drupal are set up in the following two ways:
- If the minimum cache lifetime ≤ expiration of cached pages, this will always happen.
- If the minimum cache lifetime > expiration of cached pages, this will sometimes happen.
Acquia recommends large values for the expiration of cached pages, because Varnish obeys this value. Large values mean that most of the anonymous traffic will terminate in Varnish.
- How to purge cached pages in Varnish: Purging Varnish cache on Acquia Cloud
- How to set up the Acquia Purge module to set up smarter, partial Varnish clears to cut down on stale content: Installing Acquia Purge
- How to examine the values of the Varnish cache headers for your website page: Varnish headers for Acquia Cloud