Skip to main content

CDN cache purging and purge history

Purge clears the CDN resource cache. Use it when content on the origin is updated and waiting for natural cache expiration is not acceptable, or when CDN servers are serving stale content.

Three purge methods are available:

  1. Purge by URL to remove specific cached files without affecting other content.
  2. Purge all to remove all data from the cache.
  3. Purge by pattern to remove content selectively by specifying path patterns with the * operator.

Customer Portal cache purge

  1. 1

    Open Purge request

    In the Customer Portal, navigate to CDN → Purge → Purge request.

  2. 2

    Select a CDN resource

    Select the relevant CDN resource from the dropdown menu.

  3. 3

    Select a purge method

    Click the radio button next to the purge method, configure it as described below, then click Purge.

Purge request page with CDN resource dropdown and purge type selection

Two purge requests per resource per minute are allowed. One purge request is limited to 100 URLs, so up to 200 files can be removed from the cache per minute.

In the text area, specify one or more content URLs to purge, entering one URL per line. Each path must:

  • Start with a slash (/).
  • Not include a protocol, domain name, or wildcard (*).
  • Include query strings if the CDN resource cache is configured to consider the query string.

To purge https://www.example.com/pictures/icon.jpg?size=small, enter /pictures/icon.jpg?size=small.

Purge by URL section with text area for entering URLs

Click Show more under the text area to see additional recommendations.

Avoid this method in the cases below:

  • A Vary HTTP response header is present on the origin. Purge by URL deletes only one version of the file.
  • When Large files delivery optimization is enabled, Purge by URL removes only the first cached byte-range slice, which starts at byte 0.

The behavior of Purge by URL also depends on the Ignore Query string option:

  • If the value is Ignore All, do not include query parameters in the purge request.
  • If the value is Ignore All Except, only files with the parameters listed in the option are cached as different objects. Files with other parameters are cached as one object. In this case, include the listed parameters in any order. Do not include other parameters.
  • If the value is Ignore Only, files with the parameters listed in the option are cached as one object. Files with other parameters are cached as different objects. In this case, include other parameters (if any) besides the listed ones in any order.

Click Purge to apply.

One purge request per resource per minute is allowed. After a full purge, subsequent cache misses cause CDN servers to fetch content from the origin, which can sharply increase origin load. For large amounts of content, use Purge by URL or pattern instead.

Select Purge all and click Purge.

One purge request per resource per minute is allowed. One purge request is limited to 10 patterns.

In the input field, enter path patterns without a domain name. Use the * operator to match any number of characters. Each path must start with / and be on a separate line. If a query string is not included in a pattern, the purge covers all query string variants of matching files.

Purge by pattern radio button selected with pattern text area

For example:

TargetPattern
One file (all query string variants)/static/image.jpg
All files in a folder/static/*
Files by extension/static/*.jpg
Files under a matching path segment/img/*/files
Files by extension under a path/img/static/*.jpg

To target a file with a specific query string, include it in the path: /static/image.jpg?VERSION.

Click Purge to apply.

Purge history

Purge history stores requests for the past month only.

Navigate to the Purge history page and filter the requests.

FilterDescription
Search by CNAMECNAME of the CDN resource
TypePurge by URL, Purge all, or Purge by pattern
StatusIn progress, Successful, Failed, or Status report disabled
DateTime period up to one month

When CDN caching is set to CDN controlled and Cache expiry to Do not cache, the CDN does not cache content, and the purge status changes to Failed after 45 minutes.

Purge the CDN cache by URL, pattern, or all, and retrieve purge history via the REST API.

An API token is required.

Set the required environment variables. The CDN resource ID is available in the Customer Portal under CDN → CDN Resources, or via the List CDN resources API call. In the SDK examples, 12345 is that resource ID.

export GCORE_API_KEY="{YOUR_API_KEY}"
export CDN_RESOURCE_ID="{YOUR_RESOURCE_ID}"

Purge by URL

Remove specific files from the CDN cache. Two purge requests per resource per minute are allowed; one request is limited to 100 URLs. URLs must start with / and must not include the protocol or domain name. Include query strings if the CDN resource caches content per query string.

from gcore import CDB

client = CDB()  # Reads GCORE_API_KEY from env

client.cdn.cdn_resources.purge(
    12345,  # CDN resource ID
    urls=["/images/logo.png", "/css/style.css?ver=2.0"],
)
package main

import (
    "context"
    "fmt"

    gcore "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
)

func main() {
    client := gcore.NewClient()  // Reads GCORE_API_KEY from env
    ctx := context.Background()

    err := client.CDN.CDNResources.Purge(ctx, 12345, cdn.CDNResourcePurgeParams{
        OfPurgeByURL: &cdn.CDNResourcePurgeParamsBodyPurgeByURL{
            URLs: []string{"/images/logo.png", "/css/style.css?ver=2.0"},
        },
    })
    if err != nil {
        fmt.Printf("error: %v\n", err)
    }
}
curl -X POST "https://api.cdb-staging.cdn.orange.com/cdn/resources/$CDN_RESOURCE_ID/purge" \
  -H "Authorization: APIKey $GCORE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "/images/logo.png",
      "/css/style.css?ver=2.0"
    ]
  }'

HTTP 201 means the request was accepted. The response body echoes the submitted URLs. The purge finishes later, and its status is in purge history: In progress, then Successful or Failed.

{
  "urls": ["/css/style.css?ver=2.0", "/images/logo.png"]
}

Purge by pattern

Remove files matching a path pattern. Use the * operator to match any number of characters. Patterns must start with /. If a query string is not included in a pattern, the purge covers all query string variants of matching files. One request is limited to 10 patterns; one purge request per resource per minute is allowed.

from gcore import CDB

client = CDB()

client.cdn.cdn_resources.purge(
    12345,
    paths=["/images/*", "/static/*.js"],
)
package main

import (
    "context"
    "fmt"

    gcore "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
)

func main() {
    client := gcore.NewClient()
    ctx := context.Background()

    err := client.CDN.CDNResources.Purge(ctx, 12345, cdn.CDNResourcePurgeParams{
        OfPurgeByPattern: &cdn.CDNResourcePurgeParamsBodyPurgeByPattern{
            Paths: []string{"/images/*", "/static/*.js"},
        },
    })
    if err != nil {
        fmt.Printf("error: %v\n", err)
    }
}
curl -X POST "https://api.cdb-staging.cdn.orange.com/cdn/resources/$CDN_RESOURCE_ID/purge" \
  -H "Authorization: APIKey $GCORE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "paths": ["/images/*", "/static/*.js"]
  }'

HTTP 201 means the request was accepted. The response body echoes the submitted patterns. The result appears later in purge history.

{
  "paths": ["/images/*", "/static/*.js"]
}

Purge all

Remove all cached content for a CDN resource. One purge request per resource per minute is allowed. After a full purge, subsequent cache misses cause CDN servers to fetch content from the origin, which can sharply increase origin load. For large content sets, use purge by URL or pattern.

from gcore import CDB

client = CDB()

client.cdn.cdn_resources.purge(
    12345,
    paths=[],
)
package main

import (
    "context"
    "fmt"

    gcore "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
)

func main() {
    client := gcore.NewClient()
    ctx := context.Background()

    err := client.CDN.CDNResources.Purge(ctx, 12345, cdn.CDNResourcePurgeParams{
        OfPurgeAllCache: &cdn.CDNResourcePurgeParamsBodyPurgeAllCache{
            Paths: []string{},
        },
    })
    if err != nil {
        fmt.Printf("error: %v\n", err)
    }
}
curl -X POST "https://api.cdb-staging.cdn.orange.com/cdn/resources/$CDN_RESOURCE_ID/purge" \
  -H "Authorization: APIKey $GCORE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"paths": []}'

HTTP 201 means the request was accepted. The response body echoes an empty paths array. The result appears later in purge history.

{
  "paths": []
}

Purge history

Retrieve the history of purge requests for the past month. An HTTP 201 response only accepts a purge. Find that request here by CNAME and path, and read status. Filter by CNAME, purge type, status, or date range.

When CDN caching is set to CDN controlled and Cache expiry to Do not cache, the CDN does not cache content, and the purge status changes to Failed after 45 minutes.

from gcore import CDB

client = CDB()

history = client.cdn.list_purge_statuses(
    cname="cdn.example.com",
    purge_type="purge_by_url",
    limit=50,
)
for entry in history:
    print(entry.purge_id, entry.purge_type, entry.status, entry.created)
package main

import (
    "context"
    "fmt"

    gcore "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
)

func main() {
    client := gcore.NewClient()
    ctx := context.Background()

    page, err := client.CDN.ListPurgeStatuses(ctx, cdn.CDNListPurgeStatusesParams{
        Cname: gcore.String("cdn.example.com"),
    })
    if err != nil {
        fmt.Printf("error: %v\n", err)
        return
    }
    for _, entry := range page.Results {
        fmt.Printf("%v  %v  %v  %v\n",
            entry.PurgeID, entry.PurgeType, entry.Status, entry.Created)
    }
}
curl -X GET "https://api.cdb-staging.cdn.orange.com/cdn/purge_statuses?cname=cdn.example.com&purge_type=purge_by_url" \
  -H "Authorization: APIKey $GCORE_API_KEY"

The API returns an array of purge status objects:

[
  {
    "purge_id": 10001,
    "status": "Successful",
    "purge_type": "purge_by_url",
    "created": "2024-06-10T10:15:00Z",
    "resource": {
      "id": 12345,
      "cname": "cdn.example.com"
    },
    "payload": {
      "urls": ["/images/logo.png"]
    }
  }
]