In Cloudflare, how do you purge one corrected page from the edge cache, and how do you confirm the purge worked?
answer
- Custom Purge in the zone
- one URL, every data center
- the API's 200 is an acknowledgement
- re-request and read cf-cache-status
basics
~20 sUse purge by single-file: Custom Purge, then URL, on the zone's Caching Configuration page, or send the URL to the purge_cache API. A 200 only means Cloudflare accepted it; re-request the page and check cf-cache-status is no longer HIT.
solid answer
~40 sCloudflare recommends **purge by single-file** (purge by URL) for routine corrections. In the dashboard it is **Caching > Configuration > Custom Purge > URL**; through the API it is a `POST` to `/zones/{zone_id}/purge_cache` with the URL in `files`. The purge removes that cached object from every data center, so the next request is a `MISS` that fetches the new version from the origin and caches it again in the data center that served it. The API's `HTTP 200` says only that Cloudflare received the request, not that anything was cached or evicted, so verify by requesting the URL and checking that `cf-cache-status` is no longer the old `HIT`. Fix the origin first: a purge sent before the corrected page is live simply re-caches the old one.
code
bash · 8 linescurl --request POST \
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{"files": ["https://scores.example.com/matches/8812"]}'
# then check what the edge now serves
curl -sI https://scores.example.com/matches/8812 | grep -i cf-cache-statusgo deeper
Recall where purge by URL lives in the dashboard, that the API takes the URL in files, and that cf-cache-status should read MISS and then HIT afterwards.
Explain that the 200 is only an acknowledgement, that refills happen per data center on demand, and that purge limits are per account and shared by zones on the same plan.
Show you know the traps: purge after the origin is fixed, purge the URL a Worker fetches, the end-user URL under a Transform Rule, and browsers keeping their own copy.
Discuss when per-URL purges stop scaling for a newsroom and grouped purges by tag or prefix become the team's default, and who should hold the Cache Purge permission.
## What a single-file purge does Cloudflare keeps copies of cacheable responses in its data centers so that most visitors are answered without a trip to the **origin** (the server that really produces the page). When a sports-results site corrects a match score, the old page may still sit in many of those caches. **Purging** removes the cached copy so the next request has to go back to the origin. **Purge by single-file**, also called **purge by URL**, is the method Cloudflare recommends for everyday use. It removes the cached object for one URL from **all data centers**. Nothing is pushed out in advance: the next request for that URL in any data center is a `MISS`, Cloudflare fetches the current version from the origin, and that data center caches it again. Other data centers refill only when their own visitors ask. ## Running it from the dashboard or the API 1. Make sure the origin already serves the corrected page. If it does not, the first request after the purge re-caches the old version. 2. In the dashboard, open the zone's **Caching > Configuration** page, select **Custom Purge**, choose **URL** under **Purge by**, enter one or more URLs and select **Purge**. 3. From automation, send a `POST` to `https://api.cloudflare.com/client/v4/zones/{zone_id}/purge_cache` with a JSON body such as `{"files": ["https://scores.example.com/matches/8812"]}`, using an API token that holds the **Cache Purge** permission for the zone. 4. Verify, as described below. ## Rules the URL must follow - **The hostname is not case-sensitive**: it is converted to lowercase, so `https://SCORES.example.com/...` is treated as `https://scores.example.com/...`. - **The path is case-sensitive**: `/Matches/8812` and `/matches/8812` are different objects. - **No wildcards**: single-file purge takes exact URLs. To clear a directory use purge by prefix; to clear a group of related pages use purge by tag. - **Use UTF-8 encoded URLs.** - **A Transform Rule that rewrites the path** means you purge the visitor-facing URL, not the rewritten one. - **A URL that answers with a 301 or 302** purges only the cached redirect; the page at the destination stays cached until you purge the destination URL as well. - **A Worker that fetches another URL** caches that fetched URL, so that is the URL to purge. ## Limits Single-file purge limits apply **per account**, and every zone on the same plan in that account shares them. The URL rate is measured as a moving average. | Plan | URLs per second | URLs per request | | --- | --- | --- | | Free | 800 | 100 | | Pro | 1,500 | 100 | | Business | 1,500 | 100 | | Enterprise | 3,000 | 500 | ## Verifying the purge The purge endpoint answers `HTTP 200` when Cloudflare has **received** the request. That does not confirm that the URL was cached in the first place, or that anything was evicted. Verify instead: - Request the URL (for example with `curl -sI`) and read the `cf-cache-status` response header. Straight after a purge it should be `MISS`; the following request from the same location should be `HIT` again, now serving the corrected page. - If you still see an old `HIT`, compare the exact URL: a different query string, a different path case or a URL that is really a redirect are separate cached objects. - In logs or analytics, a short burst of `MISS` responses for that URL across many locations right after the purge is the expected signature: each data center refills on its own first request. - Remember what a purge does not touch: **browsers' own caches**. A visitor whose browser stored the page for its browser lifetime keeps seeing it until that copy expires or they reload. Short browser lifetimes on pages that get corrected keep this window small. ## When one URL is the wrong tool Purge by URL is precise and cheap for the origin, because only the named objects are refetched. But a correction rarely changes only one URL. The match page, its JSON feed and the league tables that quote the score are all separate objects, and so are variants stored under other cache keys. For those cases Cloudflare offers **purge by tag**, **purge by prefix** and **purge by hostname**, and finally **purge everything**, which is a last resort because every request afterwards goes to the origin until the caches refill.
- Does a Cloudflare purge also remove the page from visitors' browsers?No. A purge acts on Cloudflare's cache only. A browser that stored the page keeps using it until its own lifetime, set by the Browser Cache TTL or the `Cache-Control` the browser received, runs out, or until the visitor reloads. Pages that get corrected should carry a short browser lifetime even when the edge keeps them longer.
- Right after a URL purge the old score came back. What usually went wrong?The purge ran before the origin served the fix, for example while a CMS was still publishing or a replica lagged, so the first request after the purge cached the old page again. Purge after the origin answers with the corrected content. A Worker in front can cause the same symptom when you purge the visitor URL instead of the URL the Worker fetches.
- How many URLs can you purge, and how fast?One request carries up to 100 URLs, or 500 on Enterprise. The rate is per account and shared by all zones on the same plan: 800 URLs a second on Free, 1,500 on Pro and Business, 3,000 on Enterprise, measured as a moving average.
- A 200 from the purge API proves the page was evicted everywhere.
- Purging a URL also clears visitors' browser caches.
- Single-file purge accepts wildcards such as /matches/*.
- Purge first, then deploy the corrected page to the origin.
- After a purge Cloudflare pushes the new page to every data center at once.