PCsuggest

  • Quick tip
  • SECURITY
  • NETWORKING
  • OpenWrt
  • HARDWARE

Check Cloudflare cache status easily with command line tools

Updated - August 26, 2019 by Arnab Satapathi

Cloudflare is an integrated CDN, DNS server, Web reverse proxy Web firewall, DDoS protection service and many more, a very common name among webmasters.

However Cloudflare is mostly used as a CDN service and reverse proxy. So, checking the cache status is important to know if the Clocdflare caching mechanism is actually working or not.

Here we'll discuss about how to check the Cloudflare cache status of a URL, obviously which being served by Cloudflare.

Contents

  • Check Cloudflare cache status
  • A shell script to do the same quickly
  • Conclusion

Check Cloudflare cache status

On Linux, UNIX or macOS it's very easy to check the cache status with the cURL or wget command.

The idea is to fetch the web page with any of these commands, retrieve the response header, then filter out the header with grep command.

An example below using this very site, as it relies on Cloudflare heavily.

wget -qSO /dev/null https://www.your-url.com/file1.js 2>&1 | grep -i 'CF-Cache-Status'

The output cache status could be HIT, MISSED, EXPIRED or others, here's the detailed article about the meaning of different status.

check cloudflare cache status command line

As a note, sometimes you won't get any output to show the cache status. Specially for those file types which are not normally cached by Cloudflare. As example HTML files, dynamic contents and content with query strings.

I'm using the wget command this time. If yo're a little familiar with this command, then it should be very easy to understand the flags I'm using.

The -q is to suppress the output, the -S to show the server headers and the -O to specify an output file, which is /dev/null in this case.

amazon prime logo
Try AmazonPrime for free
Enjoy free shipping and One-Day delivery, cancel any time.

The exact thing could be achieved with the cURL command, an example below.

curl -svo /dev/null https://your-url.com/ 2>&1 | grep -i 'cf-cache-status'

Also Read - How to clear CloudFlare cache

A shell script to do the same quickly

Well, typing a bunch of commands is not exactly handy when you've to do the same many times.

So, here's the idea of a very simple script, save it as any name you want, and make it executable.

#!/bin/sh
wget -qSO /dev/null $@ 2>&1 | grep -i 'cf-cache-status'

I've saved it as cf_cache_check, and the usage is simple.

chmod +x cf_cache_check
./cf_cache_check http://your-url.com/

Or even better, copy it to the /usr/local/bin/ directory after making it executable.

Conclusion

The script is just the beginning of an idea, you can modify it to quickly check many other Cloudflare related issues. As example, you can easily check Cloudflare SSL and HTTP/2 support with cURL.

Filed Under: coding, Quick tip

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © PCsuggest.com · All rights reserved.

  • Home
  • About
  • Contact
  • Privacy Policy
  • Sitemap