How to test if Drupal 8 pages are being cached (and anti-spam modules)

As a brief note today, if you want to know if your Drupal 8 web pages are being cached, take a look at the headers that are returned by your Drupal 8 URLs. Here’s an example using the curl command:

$ curl -I http://your-drupal-url-here

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 15 Apr 2018 02:09:03 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Cache-Control: must-revalidate, no-cache, private
X-Drupal-Dynamic-Cache: HIT
X-UA-Compatible: IE=edge
Content-language: en
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
expires: -1
X-Generator: Drupal 8 (
pragma: no-cache 

That last line that says “pragma: no-cache” means that the page isn’t being cached. If the page is being cached by the Drupal 8 system you’ll see this instead of that:

X-Drupal-Cache: HIT

I just learned that when I installed a couple of anti-spam modules (Honeypot and reCAPTCHA) on this website. Before I installed the modules I saw the X-Drupal-Cache: HIT message, but after I installed them I saw the “pragma: no-cache” output when looking at the request headers with curl.

As for now I haven’t decided how to solve my comments spam problem, but if you want to know if your Drupal 8 pages are being cached, I can confirm how this works.