Use the purge feature to invalidate cached resources on CDN edge nodes and force them to fetch the latest resources from your origin server. This is useful for scenarios such as updating content, publishing new resources, removing non-compliant content, and applying domain configuration changes. Use the prefetch feature to cache popular resources on edge nodes ahead of peak traffic, reducing the load on your origin server.
How it works
Resource purge
A purge operation sends a cache invalidation command to edge nodes rather than directly deleting files. When an edge node receives the command, it marks the matching cached resources as "invalid" or "expired." The next time a user requests the resource, the edge node detects that the cache is invalid, performs an origin fetch to retrieve the latest version, and serves it to the user while caching the new version.
Default purge method in the console: When you perform a directory purge or regex-based purge in the CDN console, the system uses a soft purge by default. A soft purge only marks the cache as expired. When the edge node performs an origin fetch, it includes an If-Modified-Since or If-None-Match header in the request. If the origin server returns a 304 Not Modified response, the edge node retains the old cached copy. This method saves origin fetch traffic but may cause users to access stale content in scenarios such as same-name file updates, non-compliant content removal, or after configuration changes. To completely purge the cache, we recommend calling thepurgeObjectCaches API operation and setting theForce parameter totrue to perform a force purge.
Use cases
Resource updates and releases: After you update or upgrade resources on your origin server, submit the corresponding URLs or directories for a purge to ensure users can access the latest content, which is then cached on the edge nodes.
Non-compliant resource removal: If your website has non-compliant content, simply deleting it from the origin server is not enough, as it may still exist in the cache of edge nodes. You must perform a URL purge to purge the cached resources and ensure the non-compliant content is removed promptly.
Resource prefetch
A prefetch operation is a pull-based mechanism that causes edge nodes to proactively fetch resources from your origin server and cache them. It is not a push from the origin server. Prefetching improves the initial access speed for new resources or event pages and reduces origin fetch pressure during product or event launches, thereby protecting your origin server.
Prefetch mechanism: By default, a prefetch operation caches resources on Tier-2 origin-pull nodes (the L2 cache layer) instead of distributing them to all L1 edge nodes. When a user first accesses a resource, the L1 edge node pulls the content from a Tier-2 origin-pull node or the origin server and caches it. Therefore, prefetching primarily reduces the load on your origin server. Comprehensive cache coverage on L1 edge nodes depends on actual user access patterns. Only after a user's request triggers an L1 node to cache the content locally can subsequent users in the same region benefit from a direct cache hit from that L1 node.
Use cases
Initial CDN setup: After adding your domain to CDN, prefetch popular static resources to edge nodes. When users request these resources, the edge nodes can respond directly, which eliminates slow initial load times and improves user experience.
Launch promotional events: Before a major event, prefetch all static resources for the event pages. When the event starts, all static resources are already cached on edge nodes and can be served directly, ensuring fast page load times.
Release installation packages or large files: Before releasing a new version or an update package, prefetch the resources to edge nodes. After the product goes live, edge nodes serve download requests directly, which improves download speeds and reduces the load on your origin server.
Prefetch cache hierarchy and expected results
A prefetch operation primarily caches resources on L2 aggregation nodes, not on all L1 edge nodes (POPs). When a user requests a prefetched resource for the first time, the L1 POP retrieves it from the L2 node or the origin server. Therefore, the primary purpose of prefetching is to reduce origin server pressure, not to guarantee immediate cache hits on all L1 POPs.
Cost evaluation: Prefetching helps improve cache hit rates. However, for small files or non-popular resources, evaluate the prefetch cost carefully. Prefetching generates origin fetch traffic, which is roughly equal to the file size multiplied by the number of L2 nodes.
Prerequisites
Permissions: To call purge and prefetch API operations (such as
RefreshObjectCachesandPushObjectCache) or perform these operations in the console, a RAM user must have thecdn:RefreshObjectCaches(for purge) andcdn:PushObjectCache(for prefetch) permissions. We recommend that you follow the principle of least privilege and grant only the permissions required for your business. For more information, see Authorize a RAM user to purge and prefetch resources.URL format: If a URL contains non-ASCII characters, such as Chinese characters or spaces, the URL must be percent-encoded by using
UTF-8. Otherwise, the purge or prefetch task may not take effect.Example: If a file on your origin server has the path
https://www.example.com/文档/说明.pdf, encode it ashttps://www.example.com/%E6%96%87%E6%A1%A3/%E8%AF%B4%E6%98%8E.pdfbefore submitting the purge task.
Usage notes for purge and prefetch
Task timing: Both cache purge and prefetch tasks generate origin fetch traffic. We recommend that you run large-scale cache purge and prefetch tasks duringoff-peak hours.
Submitting apurge task by using either the primary domain or any associated domain invalidates the cache for all associated domains.
Submitting aprefetch task by using the primary domain prefetches content only for the origin-pull node group of the primary domain. To also prefetch content for associated domains, submit a ticket to confirm if the origin-pull node groups for the primary and associated domains are the same. If they are, prefetching the primary domain is sufficient.
Rewrite access URL: If you have configured a rule torewrite an access URL, nodes generate the cache key based on the rewritten URL. Therefore, you must submit the rewritten URL for purge and prefetch operations.
Purge and cache rules: A URL purge only invalidates specific cached resources on POPs. It does not delete or modify the directory-level cache rules configured in the console.
Origin server independence: Purge operations target the CDN POP cache and do not support purging the cache from a specific origin server. CDN abstracts the differences between multiple origin servers, and purge operations apply uniformly to all matching resources across all nodes.
Purging URLs with ignored parameters: If a domain name is configured with a "parameter filtering" cache rule, make sure the purge URL matches the actual cache key, or use a directory purge. During canary releases where old and new versions coexist, you can purge the URL with version parameters to retrieve the latest content.
Costs
The purge and prefetch features do not incur any operational fees.
However, both operations trigger edge nodes to pull resources from the origin server, which generates origin fetch traffic and requests. Billing for this traffic and these requests depends on your origin server type:
If your origin server is Alibaba Cloud OSS, you are charged for origin fetch traffic and origin fetch requests based on OSS billing rules.
If your origin server is an ECS instance or another server, you are charged based on its network bandwidth or traffic plan.
Large-scale purge or prefetch operations, especially when performed within a short period, can increase origin fetch costs. Evaluate the potential cost impact before performing these operations.
Procedure
purge resources
Log on to theCDN console.
In the left-side navigation pane, click Purge and Prefetch.
On the Purge/Prefetch tab, select Purge as the operation type.
Select a purge method and submit the task.
purge method | Description |
URL purge | Purpose: Invalidate the cache for one or more specific files.Action: In the content input box, enter the full URLs, including |
Directory purge | Purpose: Invalidate the cache for all files and subdirectories under a specified URL directory.Action: Enter the full directory URL, which must end with a forward slash ( |
Regex-based purge | Purpose: Invalidate the cache for resources in bulk by matching URL paths with a regular expression. This is useful for batch-purgeing resources based on version numbers, file types, or path segments.Action: Enter a URL that contains a regular expression. Example: |
How to purge an entire site (full-site purge or root directory purge)
CDN does not offer a one-click full-site purge option, but you can achieve this through the following methods:
Directory purge: Select Directory as the purge method and enter the root directory URL of your domain name (for example,
https://www.example.com/). The URL must end with a forward slash (/).Forced purge (API): If some POPs still serve stale content after a directory purge, call the Cache Purge API (
RefreshObjectCaches) and set theForceparameter totrue. A forced purge unconditionally removes the cached resources from all POPs, forcing an origin fetch on the next request.NoteThe
Forceparameter is not available in the console purge form. To perform a forced purge, use the API or SDK.ClickSubmit to start the purge task.
Once submitted, a purge task cannot be canceled.
A purge task typically takes 5 to 6 minutes to propagate across the entire network. If a cached resource has an expiration time shorter than this, you do not need to manually purge it.
If you enableautomatic CDN cache purge in the OSS console, you cannot view automatic purge tasks initiated from OSS in the CDN console.
Prefetch resources
Log on to the CDN console.
In the left-side navigation pane, clickPurge and Prefetch.
On the Purge/Prefetch tab, selectPrefetch as the operation type.
In the content input box, enter the full URLs of the files to prefetch, one per line. Directory prefetch is not supported. Example:
https://www.example.com/install/package.zip.ClickSubmit to start the prefetch task.
Once submitted, a prefetch task cannot be canceled.
The completion time for a prefetch task depends on the file size, number of files, and origin server performance. It typically takes 5 to 30 minutes.
Notes on prefetching OSS files
When your origin server is OSS, take note of the following URL requirements:
URL format: You must enter the full URL of the CDN-accelerated domain name (for example,
https://cdn.example.com/path/file.zip). Do not enter the internal or public endpoint URL of the OSS bucket (for example,https://examplebucket.oss-cn-hangzhou.aliyuncs.com/...).Signature parameters: Prefetch URLs must not contain OSS temporary signature parameters such as
Expires,OSSAccessKeyId, orSignature. These are temporary authorization parameters that cause prefetch tasks to fail.Origin server response status code: A prefetch task requires a
200status code from the origin server. If the origin server returns a308redirect or any non-200status code, the prefetch task fails. For example, if a missing trailing slash in the URL causes a redirect, add the trailing slash and resubmit the task.
Parameter | Description |
Prefetch type | Only URL prefetch is supported. Directory prefetch is not supported. |
URL | URLs must include the Daily URL prefetch quota: By default, you can submit up to 1,000 URLs for prefetch per day per account. If your account's daily peak bandwidth exceeds 200 Mbps, you can request a quota increase. Alibaba Cloud will evaluate and configure your quota based on your business needs. You can submit up to 100 URLs per prefetch task. Prefetch queue rule: The maximum prefetch queue size for each account is 100,000 URLs. URLs are prefetched in the order they are submitted. When the number of URLs in the prefetch queue reaches 100,000, the system rejects new prefetch tasks. Prefetch speed: The prefetch speed depends on the average file size. Smaller files are prefetched faster. |
Automate purge or prefetch tasks
We recommend that you use an automated script to purge and prefetch resources in the following situations:
You do not have developers to automate tasks, and submitting them manually results in high operational costs.
You have too many URLs to purge or prefetch, and submitting them in batches is inefficient.
You need to manually or programmatically check whether purge and prefetch tasks are running as expected.
Verify results
Manual query
On the Operation Record tab, you can view detailed records and the progress of your purge or prefetch tasks. A progress of 100% indicates that the task is complete. purgeing or prefetching a large number of resources can extend the task completion time.
API query
Call the DescribepurgeTasks API operation to query the status of a purge or prefetch task.
Command-line verification
Run the commandcurl -I <URL>. The output is similar to the following:

If the X-Cache header is present:
If the value of
X-CacheisHIT, the request hit the cache, indicating that the prefetch was successful.If the value of
X-CacheisMISS, the request did not hit the cache. The prefetch task is not complete or has failed. Try prefetching the resource again.
If the X-Cache header is not present:
If the X-Cache header is absent, it indicates that the resource is not accelerated by CDN. SeeAdd a domain name to Alibaba Cloud CDN to add the domain of the URL to Alibaba Cloud CDN before you prefetch the resource.
Limitations
Purge and prefetch features are subject to quotas. The system rejects tasks that exceed the quota. To request a quota increase, go to Quota Management.
Operation type | Method | Quota | Manage quota |
purge | URL purge | 10,000 URLs per account per day | If you submit a request for a quota increase, the review typically takes one business day. For more information about managing your quota, see quota management. |
Directory purge | 100 paths per submission; 100 paths per minute per domain | ||
Regex-based purge | 20 URLs per account per day | ||
Prefetch | URL prefetch | 100 URLs per submission; 1,000 URLs per account per day |
Best practices for large-scale prefetching
Directory prefetch is not supported: Only specific file URLs are supported for prefetch. You cannot submit directory paths that end with a forward slash (
/).Prioritize large files: If your origin server (such as OSS) contains a large number of files, we recommend that you prefetch only large files such as installation packages and videos. Small files typically do not need to be prefetched because they are cached on POPs upon the first user request.
Quotas and queue: Each account has a default daily quota of 1,000 URL prefetch tasks. The prefetch queue can hold a maximum of 100,000 URLs. To request a quota increase, use quota management.
Origin fetch traffic warning: A prefetch triggers all L2 aggregation nodes to fetch resources from the origin server, which can generate significant origin fetch traffic (roughly equal to file size × number of L2 nodes). We recommend that you prefetch only critical resources before peak traffic periods. For video workloads, consider using range-based origin fetch optimization instead of full-content prefetching.
CDN cache purge mechanisms
For directory and regex-based purgees, CDN provides two mechanisms: soft purge and force purge. Use them for different scenarios to manage cached content efficiently.
Soft purge (default CDN policy)
Use case: Routine content updates, such as publishing new versions of static files.
Mechanism: This is the default behavior for directory and regex-based purgees submitted through the console. When a CDN edge node performs an origin fetch, it includes an
If-Modified-SinceorIf-None-Matchheader in the request. The origin server uses these headers to determine if the resource has been updated.Effect: If the resource on the origin server has not changed, the origin server returns a
304 Not Modifiedstatus code. The CDN edge node then continues to serve the old cached copy, which consumes no origin fetch traffic. This is an optimized method that saves costs and reduces the load on the origin server. Note: If you need to completely purge the cache (for example, to remove non-compliant content, apply configuration changes, or update a file with the same name), a soft purge may not meet your needs. In such cases, use a force purge.
Force purge
Use cases: Urgent removal of non-compliant or erroneous resources, forcing a network-wide update after fixing incorrect
Cache-Controlresponse header configurations, or updating a file on the origin server that has the same name.Mechanism: To trigger a force purge, set the
Forceparameter totruewhen you call the purgeObjectCaches API. In this mode, the CDN edge node unconditionally marks the cached resource as invalid and does not perform a 304 validation check.Effect: On the next request for the resource, the CDN edge node must perform an origin fetch to get the new version, even if the file on the origin server has not changed.
API force purge parameter example:
{
"ObjectType": "Directory",
"ObjectPath": "https://www.example.com/static/",
"Force": true
}Key parameter descriptions:
ObjectType: SpecifyDirectoryorFile.ObjectPath: Specify the full directory path ending with/, or a specific file URL.Force: Set totrueto enable force purge. This clears the cache directly, bypassing the origin server'sIf-Modified-Since/If-None-Matchvalidation.
Typical use cases for forced purge
We recommend that you use forced purge (by calling the Cache Purge API and setting Force=true) in the following scenarios:
Non-compliant content or malware removal: After you delete malicious files from the origin server, you must use a forced purge or ensure the origin server returns the correct HTTP status code (such as
404) for the deleted URL. Otherwise, POPs may continue to serve non-compliant content from cache after a standard revalidation.Same-name file updates (configuration changes): If you replace a file on the origin server with a new version using the same filename, a revalidation may return a
304 Not Modifiedstatus code and continue serving the old cached content. Use a forced purge to ensure the latest content is served across all POPs.Page display issues or homepage loops: If other pages on your website keep showing the homepage or images display incorrectly, and URL purge does not resolve the issue, use a directory purge with
Force=truethrough the API.