CDN Cache Purge and Invalidation: Methods, Tags, and Reserve
When to purge vs invalidate CDN cache, which selectors to use, Cache Reserve costs, Workers cache, custom cache keys, and how to verify with CF-Cache-Status.
This page summarises Cloudflare documentation on clearing or refreshing cached content at the edge: zone-level purge and invalidate operations, Cache-Tag bulk purges, behaviour when Cache Reserve is enabled, and separate rules for Workers cache. After a content update, operators usually need either an instant removal (purge) or a softer refresh that can reuse bytes from origin (invalidation, sometimes called soft purge).
Purge vs invalidate: which operation when?
Section titled “Purge vs invalidate: which operation when?”Purge removes matching cached responses; the next request must fetch a full response from your origin. Invalidate keeps the bytes in cache but marks them stale; on the next request Cloudflare revalidates with conditional requests (ETag or Last-Modified).
Invalidation marks cached content as stale. On the next request, Cloudflare revalidates the content with your origin. If your origin responds with 304 Not Modified, Cloudflare reuses the cached content instead of downloading it again.
— Cloudflare, Invalidate cached content
Both accept the same selectors: URLs, cache tags, hostnames, URL prefixes, or everything. They use different API endpoints (purge_cache vs invalidate_cache) and behave differently on errors and stale serving.
| Aspect | Purge | Invalidate |
|---|---|---|
| Cached body | Removed | Kept, marked stale |
| Next request | Full fetch from origin | Revalidation with origin |
| Stale while revalidating | Not served | Can be served (edge), per cache settings |
| When origin is down | Cached copy gone after purge | Edge may serve stale; Cache Reserve does not serve stale while revalidating |
Use purge when cached content must not be served again. Update or remove the content at your origin before you purge it. Otherwise, the next request can cache the old version again.
Use invalidation to refresh content that might not have changed, such as a group of assets that share a cache tag.
— Cloudflare, Invalidate cached content
Invalidation requires your origin to return ETag or Last-Modified and to support conditional requests; otherwise Cloudflare may download the full response anyway. To stop serving cached content entirely, purge instead of invalidate. Invalidation and purge share the same rate limits.
Zone purge methods: purge by URL, tag, hostname, prefix, and everything
Section titled “Zone purge methods: purge by URL, tag, hostname, prefix, and everything”Cloudflare’s Instant Purge exposes several selectors. Single-file purge (purge by URL) is the recommended default for one asset; broader methods trade precision for scope.
You can now access all Cloudflare cache purge methods — no matter which plan you’re on. Whether you need to update a single asset or instantly invalidate large portions of your site’s content, you now have the same powerful tools previously reserved for Enterprise customers.
— Cloudflare, All cache purge methods now available for all plans
Anyone on Cloudflare can use:
- Purge Everything — all cached content for the zone.
- Purge by Prefix — URLs sharing a path prefix (hostname plus path, no scheme; see purge by prefix).
- Purge by Hostname — all assets on listed hosts (purge by hostname).
- Purge by URL — one URL (or many via API).
- Purge by Tag — responses that carried matching
Cache-Tagheaders (purge by cache-tags).
From the dashboard, open Configuration under Caching, then Custom Purge or Invalidate Cache for the matching action. Via API, POST to https://api.cloudflare.com/client/v4/zones/{zone_id}/purge_cache or .../invalidate_cache as described in Invalidate cached content.
Development Mode temporarily bypasses cache but does not purge files; for an instant clear, use purge, not Development Mode.
Purge by URL: dashboard limits and redirect pitfalls
Section titled “Purge by URL: dashboard limits and redirect pitfalls”Single-file purge removes the asset from the CDN in all data centers; the next request is a MISS and repopulates from origin (purge by single-file).
A successful purge request returns HTTP 200. This indicates that Cloudflare received the request — it does not confirm that Cloudflare cached the targeted content or evicted any content. To verify a purge, request the asset after purging and confirm that CF-Cache-Status is no longer HIT.
— Cloudflare, Purge cache
If the URL returns a 301/302, single-file purge clears the redirect response, not the destination URL — purge the final URL after following redirects (purge by single-file). With Transform Rules that rewrite paths, use the end user (non-transform) URL for single-file purge; for prefix purge, use the post-transform (origin) URL (purge by prefix, purge by single-file).
Cache-Tag: tag responses and purge in bulk
Section titled “Cache-Tag: tag responses and purge in bulk”Attach tags on the response with the Cache-Tag header (comma-separated). Cloudflare stores tags and strips the header before the client sees it (Workers Cache-Tag, purge by cache-tags).
Cache-tag purging makes multi-file purging easier because you can instantly bulk purge by adding cache-tags to your assets, such as webpages, image files, and more.
— Cloudflare, Purge cache by cache-tags
Tag rules to remember: printable ASCII only, no spaces; up to 1024 characters per tag in API calls; case-insensitive matching. Invalid tags are silently dropped at cache time (Workers configuration). If you never set Cache-Tag, you cannot purge by tag until new responses are cached (Workers debugging).
Example invalidation by tag:
curl --request POST \ "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/invalidate_cache" \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --header "Content-Type: application/json" \ --data '{"tags":["product-images"]}'(Source: Invalidate cached content instead of purging it.)
Custom cache keys: when purge by URL fails
Section titled “Custom cache keys: when purge by URL fails”Cache Rules that build a custom cache key from headers, cookies, or other request fields break dashboard single-file purge, because the dashboard cannot send those key parts.
Custom cache keys that include headers, cookies, or other request properties will prevent dashboard single-file purge from working, because the dashboard cannot send those values in a purge request.
— Cloudflare, Cache Rules and cache keys
What to do instead: API purge by URL with a headers object matching the cache key (purge cache key resources); or purge by host, prefix, tag, or everything (unaffected by custom keys). Enterprise zones can purge some variants from the dashboard using Advanced device type or country when invalidating or purging by URL (Invalidate cached content).
Rules that only match GET may not run on purge requests unless the expression also allows PURGE (purge by single-file). Image URL rewrites through /cdn-cgi/image/ can make single-file purge report success without clearing the image unless purge requests are excluded from the rewrite (Images troubleshooting).
Workers fetch URLs vs visitor URLs
Section titled “Workers fetch URLs vs visitor URLs”For assets cached from a Worker fetch() to another URL, purge the fetch URL the cache stores, not only the visitor URL (How the Cache works). Zone purge does not clear Workers Cache entries; use ctx.cache.purge() or invalidate() inside the Worker (Invalidate cached content, Purge and invalidate the cache).
Cache Reserve: purge cost vs invalidate and storage
Section titled “Cache Reserve: purge cost vs invalidate and storage”Cache Reserve is a persistent upper tier (R2-backed). Purge and invalidation interact with it differently from the edge cache alone.
Purge requests now force a cache miss for Cache Reserve content, regardless of purge type. Previously, purging by cache tag, hostname, prefix, or everything marked matching Cache Reserve content for revalidation. Purging by URL already removed content from Cache Reserve and is unchanged.
— Cloudflare, Purge now forces a cache miss for Cache Reserve content
After any purge type, the next request for affected content is a Cache Reserve miss; origin must send the full body even if unchanged, then Cloudflare writes to Cache Reserve again (Class A operation). Purge by URL deletes from Cache Reserve; purge by tag, hostname, prefix, or everything does not delete stored objects immediately — storage costs continue until replacement or retention ends (Cache Reserve purge behavior, Cache Reserve operations).
Purge requests are free operations. Invalidation requests can result in Class A operations.
— Cloudflare, Purge and invalidation
Use invalidate when you want to keep Reserve bytes and revalidate: a 304 Not Modified reuses stored content and cuts origin egress compared with purge, but Class A charges can still apply when stored content updates (Invalidate cached content). To wipe all Reserve storage, use the Cache Reserve clear flow (zone setting off, then clear API) — distinct from everyday purge.
Workers cache: ctx.cache.purge() and ctx.cache.invalidate()
Section titled “Workers cache: ctx.cache.purge() and ctx.cache.invalidate()”Workers Caching is scoped to the Worker and entrypoint that wrote the cache. Dashboard and zone purge_cache / invalidate_cache do not affect it (Purge and invalidate the cache).
purge() accepts purgeEverything, tags, and/or pathPrefixes (paths only, no scheme or host). invalidate() uses the same selectors but keeps bodies and triggers conditional revalidation to the Worker (Workers purge modes). There is no purge-by-host mode in Workers cache — use tags, path prefixes, or purgeEverything (Workers limitations).
ctx.cache.purge() shares the zone purge rate-limit system but applies Free tier limits for Workers cache regardless of account plan (Workers limitations). Purges propagate globally like zone Instant Purge (Purge propagation).
For local development, Miniflare offers purgeCache() on the test instance.
Account limits and bot scores on purge requests
Section titled “Account limits and bot scores on purge requests”All plans share the same purge options; limits depend on plan (Purge cache availability):
| Plan | Bulk purge / invalidation rate | Single-file URLs (approx.) |
|---|---|---|
| Free | 5 requests / minute | 800 URLs / second |
| Pro | 5 requests / second | 1500 URLs / second |
| Business | 10 requests / second | 1500 URLs / second |
| Enterprise | 50 requests / second | 3000 URLs / second |
Bulk requests allow up to 100 tags, hostnames, or prefixes per call (Enterprise bucket size 500). Prefix purge is limited to 31 path segments and 100 prefixes per request; query strings and fragments are not valid prefix selectors (purge by prefix).
All HTTP purge requests will not receive a bot score.
— Cloudflare, Bot Management skips
Common mistakes
Section titled “Common mistakes”- Purging the visitor URL while the cached object is keyed on a Worker
fetchURL (How the Cache works). - Expecting dashboard single-file purge to work with header/cookie cache keys without an API purge that includes those headers (Cache Rules).
- Using purge everything when purge by tag or invalidate would limit origin load (Purge everything).
- Frequent bulk purge on Cache Reserve zones, causing full origin fetches and Class A rewrites instead of invalidate (Cost impact).
- Assuming HTTP 200 on purge means the asset was cached at the edge (Purge cache).
- Relying on zone purge to refresh Workers Cache (Invalidate cached content).
How to check this on your site
Section titled “How to check this on your site”- After purge or invalidate, request the asset and inspect the
CF-Cache-Statusresponse header — purged content should show MISS (or EXPIRED with Tiered Cache) on the first request (Purge cache, purge by cache-tags). - Confirm you targeted the correct URL (fetch URL for Worker-cached assets, final URL after redirects, correct transform/pre-transform URL) per How the Cache works and purge by single-file.
- If investigating cache fill after a purge, wait for repopulation — the first request per POP is MISS (Investigate uncached responses).
- With Cache Reserve, review operations and storage in Cache Reserve Analytics after large purges or invalidations.
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page looks wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are questioning so it can be corrected or explained.