PURGE CACHED URLS FROM A CLOUDFLARE ZONE
This guide shows you how to remove specific URLs from Cloudflare's edge cache for one zone. It also shows how to purge the whole zone when a targeted purge is not enough.
Prerequisites
- A Cloudflare API token with Cache Purge permission for the zone, stored in a
vault named
cloudflareunder the keyCLOUDFLARE_API_TOKEN(see Storing Secrets) - The zone's ID, from the zone's overview page in the Cloudflare dashboard
Pull the extension
swamp extension pull @webframp/cloudflareThe output looks like:
INF extension·pull: Pulling "@webframp/cloudflare"@"2026.10.14.1"
INF extension·pull: Identity verified: "@webframp/cloudflare"@"2026.10.14.1"
INF extension·pull: Pulled "@webframp/cloudflare"@"2026.10.14.1"
INF extension·pull: Extracted 14 files:Define the cache behavior
Create a @webframp/cloudflare/cache behavior named cf-cache (see
Create and Run a Behavior).
Its two required global arguments are the token reference and the zone ID:
globalArguments:
apiToken: "${{ vault.get('cloudflare', 'CLOUDFLARE_API_TOKEN') }}"
zoneId: "023e105f4ecef8ad9ca31a8372d0c353"If you manage more than one zone, define one cache behavior per zone, or use the factory pattern.
Purge specific URLs
urls is an array of strings, so pass it with the :json= suffix and list each
URL in full:
swamp behavior run cf-cache purge_urls \
--input 'urls:json=["https://example.com/index.html","https://example.com/assets/app.css"]'This asks Cloudflare to drop those URLs from the zone's cache and writes the
result to the purge resource.
If the zone is on an Enterprise plan, purge_tags and purge_prefixes take
tags and prefixes arrays in the same form. Use them to purge by Cache-Tag
header or by URL prefix.
Purge the whole zone
If targeted purges do not clear what you need, purge everything cached for the zone:
swamp behavior run cf-cache purge_allThis removes all cached content for the zone and writes the result to the
purge resource. Until the cache refills, requests go to the origin, so origin
load rises.
Review the purge results
Each run stores its result as Swamp data on cf-cache. To find and compare
earlier purges, see
Query and Manage Data.