0

I've a Drupal 8.6.9 site running on Apache 2.4 and PHP 7.2. I've enabled the internal page cache, the dynamic page cache, and the BigPipe module in an effort to tease out some more performance.

I've set max-age to 1 day, under /admin/config/development/performance.

On my local development site (drupalvm, Ubuntu 16.04) I can see X-Drupal-Cache: HIT and a visible improvement in performance, but on the hosting server, also Ubuntu 16.04, I only ever see X-Drupal-Cache: MISS.

As far as I can tell, there's nothing amiss in settings.php on the live server, the Drupal config is identical, so there must be something amiss in the Apache settings, perhaps.

Has anyone come across this before where cache works on one environment, but not another?

  • 2
    FYI: Max-Age does not work together with "Internal Page Cache" for anonymous users – Hudri Feb 13 at 17:29
2

My guess is during your testing you're visiting the page for the first time which would result in a X-Drupal-Cache: MISS (As you'd expect)

And as you've got the max-age set to 1 day your browser has now cached that response so no matter how many page visits you do for the next day you'll always see the MISS for that page (Because your browsers not going back to your server to get a fresh response) So other future users/different browsers could potentially be getting a HIT response after you've now forced drupal to create its initial cache

I'm only guessing here as I haven't tried myself but would seem to make sense. You could test it out by opening the same page in a different browser after you've got the MISS on your first browser to see if that 2nd browser is now seeing HIT

  • Yes, this explains it perfectly. Instead of the browser cache this can also be CDN/Varnish in the hosting environment. Do you see the request in the access.log of the apache server? If not, you know it's served from a cache sitting in front of Drupal. – 4k4 Feb 13 at 17:04
  • Thanks for the reply, I've just tried hitting it in one browser (Chrome) as anonymous, and seeing the cache MISS, then opening a different browser (Safari) as anonymous and still see a MISS. – MuckerMarc Feb 13 at 17:18
  • Have you checked what 4k4 said? Does your production server you a middle caching system like varnish? Maybe try his Apache access log check to confirm if your server is receiving those requests – Leigh Feb 13 at 17:37
  • @4k4, Leigh - thanks for your input, we've no CDN or reverse proxy like Varnish in this case, and I can see entries in the access.log of the server for each and every request – MuckerMarc Feb 13 at 22:04
0

Just leaving this here in case it helps someone else.

In my case, the Drupal cache HTTP headers were reporting MISS due an issue with memcache on the live server. The memcached daemon wasn't running, but the memcache Drupal module was enabled and being used as the default cache. Re-installing memcache on the live server resulted in the the X-Drupal-Cache header being set as expected.

Phew!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.