With Cloudflare, you can purge your cached content either by individual resource or everything at once.
To purge Cloudflare cached content, you can:
- Remove individual resources by file, Cache-Tag, and Host
- Invalidate all resources at once
Purge individual resources
A single resource purge leaves all other resources cached, avoiding a pull of all other content from the origin server. Cloudflare recommends this option to avoid slow site performance.
Purge an individual file
Purging a single file from the Cloudflare cache immediately removes that resource and subsequent requests for that resource will re-add the latest version from the origin server.
Note: Wildcards are not supported with single file purging. So
example.com/*.js will NOT work. You need to specify the exact, full path to the file, including the
https://example.com/file.js -- those methods are distinct for cache purge purposes.
To purge a file, open the Caching app in the Cloudflare dashboard, then click Purge Cache > Purge Individual Files.
Tip: Single file cache purge will not clear objects cached with an Origin header or other custom cache keys. You will need to purge these by sending an appropriate header through an API call.
Purge by Cache-Tag
Cloudflare allows Enterprise customers to tag content in the cache and then purge all content with a specific Cache-Tag. See documentation here.
Purge by host
For most situations, Cloudflare strongly recommends using single file purging instead of a full cache purge.
Purging everything invalidates all resources immediately. Each subsequent request for any invalidated resource will go back to the origin server(s) in an attempt to revalidate the resource.
Revalidating means that it won't be necessary for Cloudflare to re-cache the resource because it matches the latest version in the server. If Cloudflare can't revalidate the resource, the cached version is replaced with the latest version from the origin. If you have many assets along with heavy traffic, you might see a substantial increase in requests to your origin and your website might slow down as a result.
To purge everything from cache, open the Caching app in the Cloudflare dashboard, then click Purge Cache > Purge Everything.
Clear the cache via the API
You can also clear the cache through the Cloudflare APIl. To learn more, see:
Purge by origin header
Cloudflare allows customers to purge content with a specific Origin Header via the API:
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/eac5272c38291a73b90766d296a62f23/purge_cache"
-H "X-Auth-Email: [email protected]"
-H "X-Auth-Key: a14d124c64d7b5ef329766d71abef81443be5"
-H "Content-Type: application/json"