The purge feature allows you to 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 useful for scenarios such as updating published resources on the origin server, removing violating content, and changing domain name configuration. The prefetch feature enables you to preload popular resources to CDN POPs before peak business hours to reduce origin server load and enhance user experience.
Feature description
Purge: Marks cached resources on all CDN POPs as invalid. When users make subsequent requests, CDN retrieves the corresponding resources from the origin server, returns them to users, and re-caches them on CDN POPs. The purge feature reduces the cache hit ratio.
Prefetch: Proactively caches resources from the origin server to CDN POPs. When you request resources for the first time, you can obtain the latest resources directly from CDN POPs without retrieving them from the origin server. The prefetch feature increases the cache hit ratio.
Scenarios
Feature | Applicable scenarios |
Refresh |
|
Warm-up |
|
Precautions
Precautions for cache purge:
Submitting many purge tasks clears a significant amount of cache, causing a sudden increase in back-to-origin bandwidth and requests. This increases load on the origin server. We recommend performing this operation during off-peak periods.
A purge task takes effect 5 to 6 minutes after being submitted. If the TTL for the resources you want to refresh is less than 5 minutes, you can wait until the TTL expires instead of performing the refresh operation.
URL purge, directory purge, and regex purge 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 cache prefetch:
After submitting and successfully executing a prefetch task, CDN POPs will immediately retrieve the required resources from the origin server. Therefore, submitting many prefetch tasks will generate many concurrent back-to-origin tasks, causing a sudden increase in back-to-origin bandwidth and requests. We recommend performing this operation during off-peak periods.
Each account's prefetch queue can include up to 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 time required for a prefetch task to complete is proportional to the size of the prefetched file. In actual practice, most prefetch tasks take 5 to 30 minutes to complete. A task with a smaller average file size takes less time.
Common precautions:
Once a URL purge or cache prefetch task is issued successfully, it cannot be stopped before the task is completed.
To use RAM users for purge and prefetch operations, you need authorization first. For more information, see Authorize a RAM user to prefetch and purge resources.
Both purge and prefetch tasks have daily quotas. For more information, see the sections about details on purge and prefetch operations below. If the daily bandwidth peak of your Alibaba Cloud account exceeds 200 Mbps, you can apply to increase the daily quota. Alibaba Cloud will assess and configure it according to your business needs.
When submitting cache purge or prefetch tasks, if your URI contains non-ASCII characters (such as spaces, Chinese characters, or special characters), you must encode the URL first. Otherwise, the content management system will not recognize the task. Please ensure that the URI you submit is in an encoded format.
For more information about purge and prefetch FAQs, see FAQ about purge and prefetch.
If you experience slow access speed after configuring CDN, we recommend first referring to the recommended documentation for troubleshooting and resolution, and then using the purge feature to update resources in CDN. For more information, see Troubleshooting slow website access after enabling Alibaba Cloud CDN.
If your website is inaccessible, see Service unavailability and exceptions.
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 type as Refresh.
Select the corresponding operation method: URL, Directory, or Regular Expression.
Enter or upload the data to be processed in the URL field.
Click Submit.
Check the purge progress.
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 method | Introduction | Precautions |
URL | URL purge clears cache files that exactly match the URL. You need to enter the complete URL path of a single file, including protocol, domain name, path, and file. For example: https://www.example.com/static/picture/earth.jpg |
|
Directory | Directory purge refreshes all files and subdirectories under the URL path you enter. You must enter the complete URL directory, ending with a slash (/). Include protocol, domain name, and path. For example: https://www.example.com/static/picture/ |
|
Regular Expression | Regular expression purge filters and purges resources using URLs with regular expressions. If a URL matches the regular expression you enter, it will be purged. 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 field.
Click Submit.
Check the prefetch progress.
Operation method | Introduction | Precautions |
URL | URL prefetch means prefetching a single file. You need to enter the complete URL path of a single file, including protocol, domain name, path, and file. For example: https://www.example.com/static/video/earth.mp4 |
|
Automatically purge or prefetch resources
If you need to automate purge or prefetch operations, see Run scripts to purge and prefetch content.
Verify results
Verify purge or prefetch task results
Manual query
View detailed records and progress of resource purge or prefetch on the Records tab. A progress of 100% indicates that the task is complete. If you have many prefetch or purge tasks, it may affect the completion progress. Please be patient.
API query
Call DescribeRefreshTaskById to check if a purge or prefetch task is complete. For more information, see DescribeRefreshTaskById.
Verify file prefetch task results
Run the following command to check the prefetch result of a file:
# Please replace this with your prefetched URL
curl -I 'http://oss.aliyundoc.com/1.png'
The system displays the following result:
When X-Cache
exists:
If
X-Cache
isHIT
, the request has hit the cache, indicating a successful prefetch.If
X-Cache
isMISS
, the request did not hit the cache, suggesting that the prefetch task is incomplete or has failed. Please try prefetching again.
When X-Cache
does not exist:
If X-Cache
does not exist, it indicates that the resource has not been connected to Alibaba Cloud CDN. Please refer to Quick start to first connect the domain name of the URL to Alibaba Cloud CDN, and then prefetch the resource.
FAQ
Related API operations
You can call API operations to purge and prefetch resources. For more information, see Purge and prefetch API.