How to clear the Cloudflare cache
If your application uses the Cloudflare CDN, you can clear its cache as needed using either the Divio Control Panel UI or the Divio API.
This is only available if:
- Your application uses Cloudflare's CDN
- The Cloudflare CDN was set up by Divio, and not independently
Purge the whole domain
Purge from the Control Panel UI
To clear the cache for a domain in your application, go to the Domains view, select the relevant domain, and click Clear CDN Cache.
The cache will be cleared within a few minutes, and you will see a success message in the dashboard.
Cache clearing is performed per domain and does not automatically apply to subdomains under the same root domain.
For example, if you clear the cache for example.com, it will not affect www.example.com. In such cases, you need to clear the cache for each domain or subdomain separately.
It will not automatically apply to media files, unless these are also served from the same domain.
Clearing the Cloudflare Cache via the Divio API
Divio provides an API endpoint that allows you to programmatically purge the CDN cache for a specific domain. This is useful for automating cache purging during new content releases, eliminating the need for manual intervention.
Instructions:
To purge the entire cache for a domain, send a POST request to:
curl -H 'Authorization: Token <TOKEN>' -X POST https://api.divio.com/apps/v3/domains/{uuid}/action/clear-cdn-cache/
You need to replace with the UUID of the domain you wish to target, and you must provide your Divio API token in the Authorization header.
You can get the UUID of the domains for your application by sending GET request to:
curl -H "Authorization: Token <TOKEN>" -X GET https://api.divio.com/apps/v3/domains/
Response:
-
A successful cache purge returns an HTTP status code of 200.
-
A 400 status code indicates the request was not processed successfully.
Purge specific prefixes
Purging by prefix is useful in different scenarios, such as:
- Invalidating a page after a change in a CMS context
- Increasing control over cached objects in a path
Example:
For the URL: https://www.example.com/foo/bar/baz/qux.jpg
Valid purge requests include:
/foo
/foo/bar
/foo/bar/baz
/foo/bar/baz/qux.jpg
/
(purges the entire domain)
Accepted input:
- ✅
/foo/bar/baz/qux.jpg
- ✅
https://www.example.com/foo/bar/baz
- ❌
www.example.com/foo/bar
→ not supported
Purge from the Control Panel UI
To purge specific prefixes:
- Go to the Domains section.
- Select the domain you want to manage.
- Click the three dots (⋮) and choose Clear CDN Cache.
- Enter a comma-separated list of prefixes to purge
(e.g./assets,/js,/css
).
Maximum 25 prefixes per request
Purge via the Divio API
You can purge prefixes programmatically using the Divio API. This uses Cloudflare’s prefix-based purge logic.
Example:
Assuming you know the domain UUID, to purge the paths /foo and /bar/script.js
here's the command for reference:
curl -H 'Authorization: Token <TOKEN>' \
-H 'Content-Type: application/json' \
-X POST \
-d '{"paths": "/foo,/bar/script.js"}' \
https://api.divio.com/apps/v3/domains/{uuid}/action/clear-cdn-cache/
Response:
- 200 OK → The purge request was successful.
The response confirms the exact cache paths that were purged. The prefixes array lists the complete paths including the domain that Cloudflare successfully cleared from its cache.
- 400 Bad Request → The input was invalid with a description of the error.
For example:
Error: "Attempt to clear cache was not performed due to a mismatch between the known domain name and the provided paths."
For API details related to Divio's domain management, please refer to the Divio API documentation.