Automatic Cache Purge

Hi, we need to purge cache from time to time.

I read there is a way to clear cache via URL: https://api.cloudflare.com/#zone-purge-files-by-url

If our API is: abcdegc
and our zone is: 1234567

Does it mean we just need to add the following to a cron job: https://abcdefg.cloudflare.com/1234567-purge-files-by-url?

Thank you so much. We are not trained coders. Consider us quite ignorant about computer stuff. Just trying to make this work.

Jing

I generally create a shell script, like purge.sh that has the curl command on one line. And then call that script from cron.

I do not know how to write such a script. Is there a alternative? Also, can the script be stored somewhere in the cloud?

If you have command line access on a server, this should work. Just make sure the script has execute permissions for everybody. It’s not a good idea to store it in the cloud because it has your API key.

#!/bin/bash
curl -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/purge_cache" \
 -H "X-Auth-Email: [email protected]" \
 -H "X-Auth-Key: API_KEY" \
 -H "Content-Type: application/json" \
 --data '{"files":["http://www.example.com/css/styles.css"]}'

I’m not sure if the syntax is perfect. The example had a lot more data for more URLs to purge.

There’s a Worker that can do a Purge Everything that executes if you hit a specific URL. You really need to get a “trained coder” to execute specialized functions such as this.

The easiest way of doing it is via the dashboard.

  1. Click on your domain
  2. Click on the blue caching icon at the top

This topic was automatically closed after 30 days. New replies are no longer allowed.