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 |
|
Prefetch |
|
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.
For more information on refresh and prefetch FAQs, see FAQ about purge and prefetch.
If you experience slow access speed or inaccessible resources after configuring CDN, it is recommended to see the troubleshooting document and handling the issue first.
Purge or prefetch resources
Purge resources
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, click Purge and Prefetch.
On the Purge/Prefetch tab, select the operation as Refresh.
Select the corresponding operation method: URL, Directory, or Regular Expression.
Enter or upload the data to be processed.
Click Submit.
Check the task progress on the Records tab.
NoteIf 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 |
|
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/ |
|
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
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, click Purge and Prefetch.
On the Purge/Prefetch tab, select the operation type as Prefetch.
Select URL as the operation method.
Enter or upload the data to be processed in the URL.
Click Submit.
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 |
|
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.
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:
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.