Why would you want to know if a site is using Cloudflare cache? If you are debugging or responding to an incident, it is easy to forget that Cloudflare might be caching a site and it will hamper your efforts. Since most hosts cache, you’ll be dealing with a host/CDN cache, Cloudflare cache, and local browser cache. Knowing how to purge or bypass those is important.
So, how can you tell if a site is using Cloudflare cache? Good news: Cloudflare returns a specific header for sites using their cache:
You can check for it with curl!
curl -sI https://example.com | grep "cf-cache-status"
You might notice some different values attached to that
cf-cache-status header: DYNAMIC, HIT, MISS, etc. You can learn about those here:
It is worth noting that the cache response you get for the homepage is not necessarily the same response you’ll get for other pages and assets on the site, but the presence of the header is a dead giveaway.
If you support a lot of sites like we do at work, you can script it with bash and get a neat list of which ones use Cloudflare cache:
for url in $(head -n800 urls.txt); do content="$(curl -sI $url | grep "cf-cache-status")" if test -z "$content" then continue else echo "$url || $content" >> cloudflare.txt fi done
This assumes a file named
urls.txt with one URL per line. It runs the curl command for each URL and only outputs a result in the text file (cloudflare.txt) if the grep is not empty.