# How to determine if a site uses Cloudflare cache with curl

- Link: https://cagrimmett.com/2022/10/15/how-to-determine-if-a-site-uses-cloudflare-cache-with-curl/
- Published: 2022-10-15T10:08:29-04:00
- Author: Chuck Grimmett

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: `cf-cache-status`

You can check for it with curl!

    ```wp-block-code
    curl -sI https://example.com | grep "cf-cache-status"
    ```

the `-sI` option there means “[silent](https://curl.se/docs/manpage.html#-s)” and“
[headers only.](https://curl.se/docs/manpage.html#-I)“

You might notice some different values attached to that `cf-cache-status` header:
DYNAMIC, HIT, MISS, etc. You can learn about those here:

![](https://i0.wp.com/developers.cloudflare.com/cf-twitter-card.png?ssl=1)

Default Cache Behavior · Cloudflare Cache docs

Cloudflare makes customer websites faster by storing a copy of the website’s content
on our servers. Caching static resources at Cloudflare reduces your server load 
and bandwidth, with no extra charges for bandwidth spikes

developers.cloudflare.com

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](https://wpspecialprojects.wordpress.com/),
you can script it with bash and get a neat list of which ones use Cloudflare cache:

    ```wp-block-code
    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.