API
The Gcore Customer Portal is being updated. Screenshots may not show the current version.
CDN
CDN
BillingCDN resources overviewOrigin groupPurgePrefetchReports
API
Chosen image
Home/CDN/Purge

Clear CDN resource cache by URL, pattern or all

About Purge

Purge is an option that allows clearing the CDN resource cache. Using Purge is helpful if you update the content on your origin and don’t want to wait until the content is updated on CDN servers naturally because it takes time. After Purge is applied, the outdated CDN server’s cache will disappear. Additionally, the option assists if your end-users receive incorrect content of your website data from CDN servers.

We provide three options for cache clearing:

  1. Purge by URL (recommended) to remove content that belongs to a particular URL from the cache without impacting other cached items.
  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 that can replace any number of symbols.

There are two ways to clear the cache: via API (use the API documentation to get more information about the request) and in the Control Panel.

Configure the Purge option

1. Go to the Purge section.

A new page opens. Do the remaining steps there.

Configure the Purge option

2. Select the CDN resource from the dropdown menu to which the content to purge belongs.

3. Select the purging type and follow the appropriate instructions below (by URL, all, or by pattern) to manage purge.

4. Click the Purge button.

Purge by URL

Note: You can make two purge requests for a resource per minute. One purge request is limited to 100 URLs. It means you can remove only 200 files from the cache in a minute.

In the text area, specify one or more content URLs to purge, entering one URL per line. Make sure to follow the URL requirements. Links 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.

For example, to purge the file https://www.example.com/pictures/icon.jpg?size=small, specify the following: /pictures/icon.jpg?size=small.

Purge by URL

We recommend using other types of Purge in the following cases:

  • If your origin contains a Vary HTTP response header. When you use Purge by URL, it will delete only one version of the file.
  • If Large file delivery optimization is enabled. When you update several files in origin without clearing the CDN cache, Purge by URL will delete only the first slice (with bytes=0…).

The configuration of Purge by URL also depends on the settings in the Ignore Query string option:

  • If the value is "Ignore All", don’t specify parameters in the Purge request.
  • If the value is "Ignore All Except", only files with the parameters listed in the option will be cached as different objects. Files with other parameters will be cached as one object. In this case, specify the listed parameters in any order in the Purge request. Other parameters shouldn’t be specified.
  • If the value is "Ignore Only", files with the parameters listed in the option will be cached as one object. Files with other parameters will be cached as different objects. In this case, specify other parameters (if any) besides the ones listed in any order in the Purge request.

Purge all

Note: You can make one purge request for a resource per minute.

To purge all files from the cache, select the "Purge All" option and click the Purge button.

Purge all

Please note that purging all files from the cache will cause a significant load on your server as CDN servers will pull all files from the origin. Therefore, if you have a large amount of content, we recommend using Purge by URL or pattern.

Purge by pattern

Note: You can make one purge request for a resource per minute. One purge request is limited to 10 patterns.

To purge files by pattern, specify the path to the file you want to purge or a path pattern without a domain name in the input line. Use the * operator, which replaces any number of symbols in your path (you can use several * operators in one request). A path must start with the / or the * symbols and each path must be on a separate line.

Purge by pattern

If you don’t specify a query string, files with all the possible query string parameters will be purged from the cache according to the path pattern.

Several types of patterns are available:

Type and explanation Purge target Purge pattern
1. Purge the selected file

Specify a file path without a domain name.
As a result, all files at cdn.site/static/image.jpg
will be purged,
including files with query string .jpg?VERSION

If you want to purge only a selected file with a query string, specify it in the file path: /static/image.jpg?VERSION
cdn.site/static/image.jpg /static/image.jpg
2. Purge the group of files from one folder

Input pattern without a domain name and * operator: /statiс/*
cdn.site/static /statiс/*
3. Purge the group of files with a certain type

Input the * operator and the file name extension .jpg
As a result, all the jpg files will be purged,
including files with the query string .jpg?VERSION
cdn.site/*.jpg *.jpg
4. Purge the group of files having a common folder in the path

Input path pattern without a domain name and use the * operator twice
cdn.site/*/static/* */static/*
5. Purge the group of files with a certain type having a common folder in the path

Input path pattern with the * operator
cdn.site/*/static/*.jpg */static/*.jpg

Configure Purge via API

We will explain in detail how to do "Purge by URL" via API calls. Examples of other Purge types (all and by pattern) can be found in the API documentation.

Method POST
URL https://api.gcore.com/cdn/resources/{{resource_id}}/purge
URL parameter resource_id
ID of the CDN resource that the content to purge belongs to
Header Bearer {{access_token}}
application/json
Payload

1. Purge by URL:

{
"urls": [
"/example1.jpg",
"/img/example2.png",
"/style.css?ver=2.0"
]
}

2. Purge all:

{

"paths": [ ]
}

3. Purge by pattern:

{
"paths": [
"/images/*"
]
}

Request parameter

paths

1. Purge by URL:

(required, string) An array of one or more content URLs to purge

2. Purge all:

An empty array.

3. Purge by pattern:

(required, string) An array of one or more content patterns started with * or / symbols.

Response

201 Created
Returns an array of the purged URLs

400 Bad Request
The user has exceeded the URL quota

401 Unauthorized
The user does not have the correct authentication credentials

429 Too many requests
The user has exceeded the request quota

To access the API and make authenticated requests, generate an access token. You can use a REST tool like cURL or Postman to send the requests. For this guide, we used Postman.

To send a purge by URL request:

1. In Postman, open a new request tab, then do the following:

a. Set the request method to POST.

b. Enter the resource URL in the request URL field. Replace {{resource_id}} with your actual value.

New request tab in Postman

2. Go to the Authorization tab and do the following:

a. Select Bearer Token from the Type dropdown.

b. Copy the generated access token and paste it into the Token field.

Authorization

3. Go to the Body tab and do the following:

a. Select raw as the data type.

b. Select JSON from the format dropdown.

c. Enter the payload in the text area. Replace the sample values indicated by {{ }} with your actual values.

Body tab

4. Click Send.

If the purge is successful, you will receive an HTTP 201 and a response message that contains a list of purged URLs.

purge is successful

If an error occurs with the request, the API will return a status code and a body that contains a description of what caused the error. Here is an example:

error occurs

Was this article helpful?

Not a Gcore user yet?

Learn more about our next-gen CDN

Go to the product page