Cache Purge

Cloudflare cache purge procedures: purge everything, selective purge, and automation

Overview

SanMarcSoft sites behind Cloudflare CDN require cache purging after deployments to serve fresh content. This applies to all sites using Cloudflare proxy (orange cloud).

Prerequisites

  • Cloudflare API token: pass cloudflare/api-token
  • Zone ID for the target domain

Procedure: Purge Everything

Use this after a full deployment when all assets may have changed.

1
2
3
4
5
6
7
8
CF_TOKEN=$(pass cloudflare/api-token)
ZONE_ID=$(pass cloudflare/zones/<domain>)

curl -s -X POST \
  "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
  -H "Authorization: Bearer ${CF_TOKEN}" \
  -H "Content-Type: application/json" \
  --data '{"purge_everything": true}'

Expected Response

1
2
3
4
5
6
7
8
{
  "success": true,
  "errors": [],
  "messages": [],
  "result": {
    "id": "purge-request-id"
  }
}

Procedure: Selective Purge (By URL)

Use when only specific files changed:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
curl -s -X POST \
  "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
  -H "Authorization: Bearer ${CF_TOKEN}" \
  -H "Content-Type: application/json" \
  --data '{
    "files": [
      "https://verifieddit.com/index.html",
      "https://verifieddit.com/assets/main.js",
      "https://verifieddit.com/assets/style.css"
    ]
  }'

Procedure: Purge by Tag

If cache tags are configured:

1
2
3
4
5
6
7
curl -s -X POST \
  "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
  -H "Authorization: Bearer ${CF_TOKEN}" \
  -H "Content-Type: application/json" \
  --data '{
    "tags": ["deployment-v1.2.3"]
  }'

Procedure: Purge by Prefix

Purge all cached assets under a path prefix:

1
2
3
4
5
6
7
curl -s -X POST \
  "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
  -H "Authorization: Bearer ${CF_TOKEN}" \
  -H "Content-Type: application/json" \
  --data '{
    "prefixes": ["https://verifieddit.com/assets/"]
  }'

Post-Deployment Purge Checklist

After every production deployment:

  1. Deploy the new version (Pulumi, wrangler, etc.)
  2. Wait 10-30 seconds for the new version to stabilize
  3. Purge the Cloudflare cache (purge everything for major releases)
  4. Verify the new version is served:
    1
    2
    3
    
    # Check response headers for cache status
    curl -sI https://verifieddit.com/ | grep -i "cf-cache-status"
    # Should show: cf-cache-status: MISS (first request after purge)
    
  5. Request the page again to re-populate cache:
    1
    2
    
    curl -sI https://verifieddit.com/ | grep -i "cf-cache-status"
    # Should show: cf-cache-status: HIT
    

Domains Requiring Cache Purge After Deploy

DomainDeployed ViaPurge After
verifieddit.comScaleway ContainerYes
sanmarcsoft.comCloudflare PagesAutomatic
trusteddit.comCloudflare PagesAutomatic

Note: Cloudflare Pages deployments automatically invalidate the cache. Manual purge is only needed for services behind Scaleway or other origins.

Troubleshooting

  • Old content still showing after purge: Browser cache may be holding stale content. Test with curl or incognito mode.
  • Purge returns error: Check API token permissions. The token needs “Cache Purge” permission for the zone.
  • Partial purge not working: Some assets may be cached at edge locations worldwide. Full propagation can take up to 30 seconds.