The cache time-to-live (TTL) specifies the length of time that resources from an origin server are cached on CDN nodes. After the TTL expires, the CDN nodes mark these resources as expired. If a client requests an expired resource from a CDN node, CDN performs an origin fetch to retrieve the latest version of the resource and caches it on the CDN node. You can configure the cache TTL for static resources based on file directories or file name extensions to meet your business requirements.
Precautions
You can modify the cache time after you add a domain name. The cache duration affects back-to-origin traffic and costs. The cache expiration time affects the frequency of origin fetches. Set the resource cache duration based on your business needs.
If the cache expiration time is too short, CDN will frequently fetch data from the origin, which increases origin server traffic. If the cache expiration time is too long, data updates will be delayed.
A resource cached on a CDN POP that is infrequently accessed (meaning the resource on the same CDN POP is not requested often by clients) may be overwritten by other more popular resources on the CDN POP before its cache expires.
By default, when a point of presence receives a static file resource in a response from the origin server, it caches the resource according to the Alibaba Cloud CDN and DCDN default cache rules and priorities.
Do not update content on your origin server using the same file name. Instead, use version numbers for synchronization.
To accurately distinguish between content before and after an update, synchronize your origin content using version numbers. This means using different file names when you update content. For example, you can use names such as img-v1.0.jpg and img-v2.1.jpg.
Procedure
Log on to the CDN console.
In the left navigation pane, click Domain Names.
On the Domain Names page, find the target domain name and click Manage in the Actions column.
In the domain's navigation pane, click Cache.
On the Cache Expiration tab, click Create Rule.

Parameter
Description
Type
Specifies the resource scope by Directory or File Extension.
Directory: Sets the same cache rule for all resources in a specific path.
File Extension: Sets the same cache rule for a specific type of file.
Object
Specifies the folder or file extension of the resources to configure.
If you set Type to Folder, follow these rules:
You can add only one folder at a time. Use a forward slash (/) to match all folders.
Enter the full path of the folder. The path must start with a forward slash (/), such as /directory/aaa.
When you select File Suffix as the type, the following rules apply:
Enter one or more file extensions. Separate multiple extensions with commas (,), such as
jpg,txt.The input is case-sensitive.
You cannot use an asterisk (*) to match all file types.
Expire In
The time that resources are cached on CDN POPs. The maximum time is 3 years. Configure this parameter based on the following rules:
For static files that are not frequently updated, such as images and application downloads, set the expiration time to more than 1 month.
For static files that are frequently updated, such as JS and CSS files, set the expiration time as needed.
For dynamic files, such as PHP, JSP, and ASP files, set the expiration time to 0 s. This disables caching.
Honor Origin Cache Policy
If this is enabled and the origin server responds with cache policy headers (including Cache-Control and Pragma), the cache policy from the origin server takes precedence.
Ignore Origin No-Cache Header
If this is enabled, the CDN POP ignores the following no-cache policy headers from the origin server response.
Cache-Control: no-store
Cache-Control: no-cache
Cache-Control: max-age=0
Pragma: no-cache
Follows POP Cache Policy
If this is enabled, the CDN POP sends the final effective cache policy in the response to the client.
Force Revalidation
This parameter takes effect only when the cache expiration time is set to 0. The effects are as follows:
Disabled (default): If the cache expiration time for CDN is set to 0, files are not cached on CDN POPs. Each request must be redirected to the origin server to fetch the content.
Enabled: If the cache expiration time for CDN is set to 0, files can be cached on CDN POPs. Each request must be redirected to the origin server to validate the cached content.
Weight
The weight indicates the priority of the cache rule. The value can be from 1 to 99. A larger value indicates a higher priority. Rules with higher priority take precedence.
NoteIf you have multiple cache rules, set a different weight for each rule to control their execution priority.
For rules with the same weight, the one created earlier has a higher priority, regardless of the rule type.
If you configure multiple cache policies, no other policies are matched after one policy takes effect.
Rule Condition
Rule conditions can identify parameters in a request to determine whether a configuration applies to the request.
Do not use conditions
If you want to add or edit rules conditions, see Rules engine.
Click OK to complete the configuration.
Default Alibaba Cloud CDN cache rules and priorities
For origin responses with the HTTP status codes 200, 203, 206, 300, 301, 308, or 410, the cache expiration time is determined by the following rules.
When a CDN POP receives a file resource from an origin server, it applies cache rules in the following order of priority. A smaller number indicates a higher priority.
If the origin server responds with
pragma:no-cache,cache-control:no-cache(orno-store, ormax-age=0), CDN does not cache the resource.The cache expiration time or status code expiration time that is set in the CDN console.
NoteIf a CDN request matches multiple rules, only one rule is applied. The priority is determined first by weight and then by creation time.
If you have multiple cache rules, you can set a different weight for each rule to control its execution priority. A larger weight indicates a higher priority.
For rules with the same weight, the rule that was created earlier has a higher priority, regardless of the rule type.
Other cache rules that are configured on the origin server. The priority from high to low is:
cache-control>expires>last-modified>ETag.If the
cache-controlheader in the response from the origin server specifies amax-ageors-maxagevalue greater than 0, thecache-controlheader is used to set the time-to-live. For example: cache-control:max-age=3600. If bothmax-ageands-maxageare present,s-maxagetakes precedence.If the origin response does not contain a
cache-controlheader but contains anExpiresheader, the cache expiration time is determined by theExpiresheader. For example: expires:Tue, 25 Nov 2031 17:25:43 GMT.If the origin response does not contain
cache-controlorExpiresbut containslast-modified, the cache time is calculated using the formula: (Current Time -last-modified) × 0.1. If the result is between 10 seconds and 3600 seconds, that result is used. If the result is less than 10 seconds, the cache time is 10 seconds. If the result is greater than 3600 seconds, the cache time is 3600 seconds.If the origin response does not contain
cache-control,Expires, orlast-modifiedbut containsETag, the resource is cached for 10 seconds.
If the data returned from the origin server does not contain any of the cache-related response headers (
cache-control,expires,last-modified, orETag), the resource is not cached by default.
Description of cache response information
Date:Indicates the time when the origin server sent the resource in a response to the CDN POP.
When the CDN POP revalidates the resource with the origin server by including the
If-Modified-SinceorIf-None-Matchheader in the origin request, the Date information is updated if the origin server returns a 304 status code.The format is Greenwich Mean Time (GMT), for example:
Sat, 19 Apr 2025 08:58:31 GMT.
X-Cache:Indicates whether the requested resource hit the cache on the CDN POP. The following table describes the possible values.
Status
Description
HITThe requested resource hit the cache on the CDN POP.
MISSThe requested resource did not hit the cache on the CDN POP. The resource was provided by the origin server.
X-Swift-Cachetime:Indicates the remaining cache time of the resource on the CDN POP, in seconds.
X-Swift-Cachetime=Ali-Swift-Global-Savetime+ Cache expiration time set for CDN -X-Swift-SaveTime.X-Swift-Cachetimeis not always equal to the cache expiration time set for CDN. The following three situations may occur:X-Swift-Cachetime= Cache expiration time set for CDN, for example, 3600 seconds.X-Swift-Cachetimeis slightly less than the cache expiration time set for CDN. For example, the cache expiration time for CDN is set to 300 seconds, butX-Swift-Cachetimeis 295 seconds. This may be because of the following reasons:High latency occurs when a Layer 1 POP fetches data from a Layer 2 POP.
The clocks on the Layer 1 and Layer 2 POPs are not synchronized.
The value of
X-Swift-Cachetimeis negative. This may be because the cache expiration time for CDN was changed. When the client sends a request, the cache on the Layer 1 POP has expired, but the cache on the Layer 2 POP has not. For example, the cache expiration time for CDN was originally 3600 seconds and was later changed to 300 seconds. If a client sends a request 600 seconds after the first request, the response header isX-Swift-Cachetime:-300. To resolve this issue, you can refresh the cache.
X-Swift-SaveTime:Indicates the time when the resource was first cached on the CDN POP that the client directly accessed. This is typically a Layer 1 POP.
The format is Greenwich Mean Time (GMT), for example:
Sat, 19 Apr 2025 08:58:31 GMT.
Ali-Swift-Global-Savetime:Indicates the time when the resource was first cached on a CDN POP. This could be a Layer 2 POP or a POP at another cache layer, depending on the site's cache architecture.
The format is a UNIX timestamp, for example:
1745053111, which represents2025-04-19 16:58:31.
HTTP cache control mechanisms
The HTTP protocol defines three types of cache control mechanisms:
Configuration examples
Example 1: To cache .txt files for 7 days, you can add a cache rule in the CDN console for the file extension "txt" and set the cache expiration time to "7 Days".

Example 2: Assume that you configure the following cache policies for the accelerated domain name demo.aliyun.com. When a CDN POP fetches the resource http://demo.aliyun.com/image/example.png from the origin, both of the following rules are matched. Because the rules have the same weight, the rule that was created earlier has a higher priority. In this case, the rule for the /image folder was created earlier, so the system applies the rule for the folder type.
