1

Been running into a weird issue with all of our Drupal 8 websites, hosted on different servers.

The pages are caching correctly, x-drupal-cache header shows a HIT as well. The page however has it's headers set to 200, instead of 304. None of the sites are live yet, so i can't provide a link.

Request Headers:

  • HTTP/1.1 200 OK
  • Date: Fri, 18 Mar 2016 20:09:41 GMT
  • Server: Apache/2.4.7 (Ubuntu)
  • Cache-Control: max-age=900, public
  • Expires: Sun, 19 Nov 1978 05:00:00 GMT (Dries' birthdate? O.o)
  • Last-Modified: Fri, 18 Mar 2016 19:49:21 GMT
  • Vary: Cookie,Accept-Encoding
  • X-Drupal-Cache: HIT
  • Keep-Alive:timeout=5, max=100
  • Connection: Keep-Alive
  • Content-Type: text/html;
  • charset=UTF-8

Debugging the code Drupal uses to serve pages with 304 headers ( lines 165 to 170 of PageCache.php ) I have found that HTTP_IF_MODIFIED_SINCE and HTTP_IF_NONE_MATCH are not being set.

Thanks!

  • Presuming status code, what are you expecting to see? 304? – Clive Mar 18 '16 at 19:56
  • 304, yeah. Editted my post to clarify. – Mike Mar 18 '16 at 19:57
  • 2
    Guessed as much, have a read through this, see if it makes sense to your situation: stackoverflow.com/questions/1665082/…. Welcome to Drupal Answers by the way :) – Clive Mar 18 '16 at 19:58
  • I'm not actually getting a 200 cache though, it says 200 OK always. Editted my post to include request headers. – Mike Mar 18 '16 at 20:28
0

A Page cache hit just means that Drupal doesn't have to rebuild the HTML but can deliver it from the cache.

That doesn't make any difference at all for your browser. The browser requests the page and gets a HTML response. As far as he's concerned, there's no caching involved.

The built in Page cache has not support for returning 304 responses. Varnish does, but I don't know too much about when that works and when it doesn't. It depends on how you refresh/request the page for example, check if your browser really sends a If-Modified-Since header and if that's in the right form (see some of the answers in the linked stack exchange issue).

  • I can fix it with Varnish or setup Nginx as a reverse proxy, but some clients choose their own hosting solutions and might not have those options available to them. I am quite positive Drupal 7 was able to set the 304 headers when caching was enabled, just trying to figure why Drupal 8 doesn't. Been digging through the code, but haven't been able to find it yet. – Mike Mar 18 '16 at 22:49
  • I'm quite positive Drupal 7 behaved exactly the same :) – Berdir Mar 19 '16 at 9:54

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.