Date Published: February 11, 2022
Varnish cache HITS and Drupal cache MISS
Issue¶
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 MI
SS. 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
MISS
. - Drupal caches the page and sends it back to Varnish with a response header indicating that it was a
MISS
. - Varnish caches the
MISS
response, which includes the X-Drupal-Cache: MISS
response 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 MISS
and 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.
Resolution¶
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.
Additional resources¶
Did not find what you were looking for?
If this content did not answer your questions, try searching or contacting our support team for further assistance.