All Products
Search
Document Center

CDN:Purge and prefetch resources

Last Updated:Dec 16, 2024

Through the purge feature, you can delete resources cached on CDN points of presence (POPs) and force the CDN POPs to retrieve the latest resources from the origin server. This is applicable for scenarios such as updating and publishing resource on the origin server, cleaning up resource with violation, and changing domain name configuration. Through the prefetch feature, you can prefetch resources to CDN POPs before peak business hours to reduce load on origin server, enhancing user experience.

Feature description

  • Purge: Mark the corresponding cached resources on all CDN POPs as invalid. When you request again, CDN will retrieve the resources from the origin server and return them to you, while re-caching the resources to the CDN POPs. The purge feature reduces the cache hit ratio.

  • Prefetch: The origin server actively caches the corresponding resources to CDN POPs. When you request the resources for the first time, you can obtain the latest resources from the CDN POPs without retrieving them from the origin server. The prefetch feature increases the cache hit ratio.

Scenarios

Feature

Applicable scenarios

Purge

  • Resource updates and publishing

    After updating or upgrading the old resources on the origin server, to prevent users from still accessing the outdated cached resources, you can submit the URL or directory of the corresponding resources for refresh. Users can directly access the latest resources and cache them to the CDN POPs.

  • Violation content cleanup

    After you delete the content with violation, origin server resources, the content is still accessible due to cached versions on the CDN POPs. You can update the cached resources through the purge by URL feature.

Prefetch

  • First-time access to Alibaba Cloud CDN

    After you first access CDN, you can choose to prefetch your hot static resources in advance. When users access the resources, they receive a direct response from the CDN POPs. This improves user access speed and reduces first access time.

  • Large-scale event

    When operating a large-scale event, prefetch the static resources involved in the event page to the CDN POPs in advance. After the event starts, all static resources accessed by users are already cached to the CDN acceleration POPs and directly responded by the acceleration POPs.

  • Installation Packages Or Other Large File Releases

    Before releasing a new version of an installation package or upgrade package, prefetch the resources to the CDN acceleration POPs in advance. After the product is officially published, the massive download requests from users will be directly responded to by the CDN acceleration POPs, improving download speed, significantly reducing origin server pressure, and enhancing user experience.

Precautions

  • Precautions for purge:

    • Submitting many refresh tasks clear a significant amount of cache, causing a sudden increase in origin bandwidth and requests. This increases load on the origin server. It is recommended to perform this operation during off-peak periods.

    • It takes about 5 to 6 minutes for a purge task to take effect after submission. You do not need to purge if the cache expiration time configured for a file or directory is less than 5 minutes. You can wait for the file or directory cache to timeout and automatically update.

    • Purge by URL, purge by directory, and purge by regex all support shared cache. When a domain name is configured with a shared cache, you can submit a purge task using the primary domain name or any associated domain name to clear the cache.

  • Precautions for prefetch:

    • After submitting and executing a prefetch task, the CDN POPs will retrieve the required resources from the origin server. Therefore, submitting many prefetch tasks will generate a large number of concurrent tasks. This causes a sudden increase in origin bandwidth and requests. It is recommended to perform this operation during off-peak periods.

    • Each account's prefetch queue can include 100,000 URLs. CDN processes prefetch tasks based on the order of URL submission. When the number of URLs waiting to be prefetched in the prefetch queue reaches 100,000, CDN will reject new prefetch tasks.

    • The actual execution time for a prefetch task from submission to completion depends on the size of the prefetch file, ranging from 5 to 30 minutes. The smaller the average file size, the faster the prefetch speed.

  • Common precautions:

    • Once a purge by URL or cache prefetch task is issued, it cannot be stopped before the task is completed.

    • To use RAM users for purge and prefetch, you need authorization. For more information, see Authorize a RAM user to prefetch and purge resources.

    • Both purge and prefetch have daily quotas. For more information, see the sections about details on purge and prefetch. If the daily bandwidth peak of your Alibaba Cloud account exceeds 200 Mbps, you can apply to increase the daily quota through Quota Management. Alibaba Cloud will evaluate and configure it according to your business needs.

Note

Purge or prefetch resources

Purge resources

  1. Log on to the Alibaba Cloud CDN console.

  2. In the left-side navigation pane, click Purge and Prefetch.

  3. On the Purge/Prefetch tab, select the operation as Refresh.

  4. Select the corresponding operation method: URL, Directory, or Regular Expression.

  5. Enter or upload the data to be processed.

  6. Click Submit.

  7. Check the task progress on the Records tab.

    Note

    If you have enabled auto CDN cache update in the OSS console, you cannot view the automatic purge tasks of OSS cache through the CDN console.

Operation

Introduction

Precautions

URL

Purges a single file by URL. You must enter the complete URL path of the specific file, which includes protocol, domain name, path, and file name. For example, https://www.example.com/static/picture/earth.jpg

  • To purge multiple files, enter each URL on a separate line.

  • Each Alibaba Cloud account can submit a maximum of 10,000 URL prefetch tasks per day.

Directory

Purges all files in the directory through the URL path you provided. You must enter the full URL directory, ending with a slash (/). The directory should include protocol, domain name, and path. For example: https://www.example.com/static/picture/

  • To purge multiple files, enter each URL on a separate line.

  • You can purge content from up to 100 directories at a time, and purge content from up to 100 directories for a domain name per minute.

  • Purges only the changed resources. When you request a resource, the system checks the Last-Modified timestamp of the resource. If it has not changed since the last request, CDN POP returns the cached version of the resource, without making a request to the origin server. If you want to purge the resource by force, see RefreshObjectCaches.

Regular Expression

Filters purge tasks through a URL with a regular expression. The purge task is run for the file if its URL matches the regular expression. For example, http://www.example.com/static/picture/[0-9][a-z].*.jpg

Prefetch resources

  1. Log on to the Alibaba Cloud CDN console.

  2. In the left-side navigation pane, click Purge and Prefetch.

  3. On the Purge/Prefetch tab, select the operation type as Prefetch.

  4. Select URL as the operation method.

  5. Enter or upload the data to be processed in the URL.

  6. Click Submit.

  7. Check the prefetch progress.

Operation method

Related introduction

Precautions

URL

URL prefetch, i.e., single file prefetch. You need to enter the complete URL path of a single file. Include protocol header, domain name, path, file. For example: https://www.example.com/static/video/earth.mp4

  • When prefetching multiple URLs, please enter one URL per line.

  • Directories ending with / are not supported.

  • An account can submit up to 100 URL prefetch tasks at a time and up to 1,000 URL prefetch tasks per day.

Automatically purge or prefetch resources

If you need to automate refresh or prefetch, see Run scripts to purge and prefetch content.

Verify results

Method 1

Check the records and progress of a purge or prefetch on the Records tab. A progress of 100% indicates that the task is complete. A large number of prefetch tasks may take some time to process.

image

Method 2

Run the following command to check the status of the prefetch task.

curl -I 'http://example.aliyundoc.com/test.json'  // Please replace this with the URL you refreshed or prefetched

The following shows an example: TB1oFf2JFXXXXa9XXXXXXXXXXXX.png

  • Prefetch refers to prefetching resources to L2 POPs. If the L2 status is "H", the prefetch is successful.

  • The first part of Via represents the L2 node status. "H" indicates a hit, meaning the file has been prefetched to the L2 node and does not need retrieving resource from the origin server.

  • The second part of Via represents the L1 node status. "M" indicates that there is no cache on the L1 node and the resource must be retrieved from the L2 node.

Method 3

Call DescribeRefreshTaskById to query the status of a purge or prefetch task.

FAQ

Related operation

You can call API to purge and prefetch resource. For more information, see Purge and prefetch.