0

I have a site which uses Drupal core anonymous caching. However, I have noticed a very strange behavior. Sometimes I will load the home page and in the response headers will be the 'X-Drupal-Cache' header. But if I reload the page again, the 'X-Drupal-Cache' header disappears. I cannot understand how this could happen.

What might be the cause?

The response headers also containL Cache-Control:no-cache, must-revalidate, post-check=0, pre-check=0, which I understand will force the browser not to use a cached version of the page.

Strange thing is that if I access the same page using curl (e.g. curl -I http://example.com/), the X-Drupal-Cache header appears each and every time.

  • 1
    Are you sure the response is coming from the server? Is your browser returning a cached page? – Shawn Conn Sep 7 '15 at 5:10
  • Is there an easy way of checking if the page was served from the browser cache? – Benjen Sep 7 '15 at 5:35
  • Depending on your browser, your networks tools should indicate where the response comes from. An alternative might be to use cURL: curl -I http://example.com/ – Shawn Conn Sep 7 '15 at 6:20
  • @ShawnConn I tried using curl and updated my original question accordingly – Benjen Sep 7 '15 at 8:56
0

The behavior you're seeing is the result of having a browser cache. After the first request, your browser caches the document and keeps track of its signature through the Etag/Last-Modified headers.

Upon subsequent requests, the browser makes a request to the server with the If-None-Match/ If-Modified-Since headers. If the document hasn't changed, the server returns a HTTP 304 Not Modified which tells the browser it's okay to serve its cached version of the page.

Because cURL doesn't have a caching mechanism, X-Drupal-Cache always appears; it needs to go directly to Drupal each time for the document.

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.