Cache Purge API

Programmatically purge cached content.


Overview

The Purge API lets you remove cached content from all edge servers. Use this after updating content that's already cached.


Create Purge Job

POST /api/v1/zones/{uuid}/purge

Purge Types

Purge All

Remove all cached content for the zone.

curl -X POST "https://nordiccdn.com/api/v1/zones/abc123/purge" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "all"}'

Purge by Path

Remove specific paths from cache.

curl -X POST "https://nordiccdn.com/api/v1/zones/abc123/purge" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "path",
    "paths": [
      "/images/logo.png",
      "/css/style.css",
      "/products/item-123/"
    ]
  }'

Purge by Wildcard

Remove paths matching a pattern.

curl -X POST "https://nordiccdn.com/api/v1/zones/abc123/purge" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "path",
    "paths": [
      "/images/*",
      "/products/*/images/*"
    ]
  }'

Response

{
  "data": {
    "id": "purge_789xyz",
    "status": "pending",
    "type": "path",
    "paths": ["/images/logo.png", "/css/style.css"],
    "created_at": "2024-01-25T10:30:00Z"
  }
}

Check Purge Status

GET /api/v1/zones/{uuid}/purge/{purge_id}

Example

curl "https://nordiccdn.com/api/v1/zones/abc123/purge/purge_789xyz" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Response

{
  "data": {
    "id": "purge_789xyz",
    "status": "completed",
    "type": "path",
    "paths": ["/images/logo.png", "/css/style.css"],
    "edge_statuses": {
      "cph-1": "completed",
      "fra-1": "completed",
      "ams-1": "completed"
    },
    "created_at": "2024-01-25T10:30:00Z",
    "completed_at": "2024-01-25T10:30:05Z"
  }
}

Status Values

Status Description
pending Purge job created, not yet processed
processing Purge in progress on edge servers
completed Purge finished on all edge servers
failed Purge failed on one or more edges

List Purge History

GET /api/v1/zones/{uuid}/purge

Parameters

Parameter Type Description
page integer Page number
per_page integer Items per page (max: 100)
status string Filter by status

Example

curl "https://nordiccdn.com/api/v1/zones/abc123/purge?per_page=10" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Response

{
  "data": [
    {
      "id": "purge_789xyz",
      "status": "completed",
      "type": "path",
      "paths": ["/images/*"],
      "created_at": "2024-01-25T10:30:00Z"
    },
    {
      "id": "purge_456abc",
      "status": "completed",
      "type": "all",
      "created_at": "2024-01-24T15:00:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "total": 25
  }
}

Rate Limits

Purge requests are rate limited:

Purge Type Limit
Purge All 10 per hour
Purge by Path 100 per hour
Paths per Request 1000 max

Integration Examples

GitHub Actions

Purge after deployment:

# .github/workflows/deploy.yml
- name: Purge CDN Cache
  run: |
    curl -X POST "https://nordiccdn.com/api/v1/zones/${{ secrets.CDN_ZONE_UUID }}/purge" \
      -H "Authorization: Bearer ${{ secrets.NORDICCDN_TOKEN }}" \
      -H "Content-Type: application/json" \
      -d '{"type": "all"}'

Laravel Deployment

// deploy.php
$response = Http::withToken(config('services.nordiccdn.token'))
    ->post("https://nordiccdn.com/api/v1/zones/{$zoneUuid}/purge", [
        'type' => 'all'
    ]);

if ($response->successful()) {
    echo "Cache purged successfully";
}

WordPress Hook

// functions.php
add_action('save_post', function($post_id) {
    $post = get_post($post_id);
    $path = wp_make_link_relative(get_permalink($post_id));

    wp_remote_post('https://nordiccdn.com/api/v1/zones/' . NORDICCDN_ZONE . '/purge', [
        'headers' => [
            'Authorization' => 'Bearer ' . NORDICCDN_TOKEN,
            'Content-Type' => 'application/json'
        ],
        'body' => json_encode([
            'type' => 'path',
            'paths' => [$path, $path . '*']
        ])
    ]);
});

Best Practices

1. Use Path-Based Purging

Prefer path-based purging over "purge all" to minimize origin load:

{"type": "path", "paths": ["/updated-page/"]}

2. Batch Paths

Combine multiple paths in one request:

{
  "type": "path",
  "paths": [
    "/product/item-1/",
    "/product/item-2/",
    "/product/item-3/"
  ]
}

3. Use Wildcards Wisely

Wildcards are powerful but can purge more than intended:

/products/*     # Purges all products
/products/123/* # Purges only product 123

4. Monitor Purge Status

For critical updates, verify the purge completed:

# Create purge and get ID
PURGE_ID=$(curl -s -X POST ... | jq -r '.data.id')

# Check status
curl "https://nordiccdn.com/api/v1/zones/$ZONE/purge/$PURGE_ID" \
  -H "Authorization: Bearer $TOKEN"