Time-to-live (TTL) is the duration for which a resource from an origin server is cached on DCDN points of presence (POPs). When the TTL ends, the resource on the DCDN POPs expires. If a client requests a resource that has expired from a DCDN POP, DCDN fetches the latest version of the resource from the origin server and caches it on the DCDN POPs. You can configure a cache TTL for static resources based on file directories or filename extensions.
Notes
After you add a domain name, you can modify the TTL value. The amount of origin traffic and the fees incurred vary based on the TTL that you specify. The resource TTL affects the origin fetch frequency.
A short TTL may cause DCDN to perform frequent origin fetches and increase loads on the origin server. A long TTL may cause resources on the POPs to become outdated.
If a resource that is cached on a DCDN POP is infrequently accessed (the same resource on the same DCDN POP is accessed at a low frequency), the resource may be overwritten by frequently accessed resources on the DCDN POP before the resource expires.
When a DCDN node receives a static file from an origin server, it processes the file based on the Alibaba Cloud DCDN default cache rules and priorities. For information about cache rules for dynamic files, see Overview of acceleration rules for static and dynamic content.
When you update a file on the origin server, we recommend that you add a version number to the file name to differentiate file versions after updates.
This way, each version of the file after an update has a unique name. For example, you can name a file img-v1.0.jpg before the file is updated and img-v2.1.jpg after an update.
Procedure
Log on to the DCDN console.
In the left-side navigation pane, click Domain Names.
On the Domain Names page, find the domain name that you want to manage and click Configure.
In the left-side navigation tree of the domain name, click Caching.
On the Cache Duration tab, click Add.
In the Cache Duration dialog box, configure a cache rule.

Parameter
Description
Type
Specify the resource scope by Directory or Filename Extension.
Directory: Sets the same cache rule for all resources in a specific path.
Filename Extension: Sets the same cache rule for resources of a specific file type.
Content
The directory or file extension of the resources for which you want to configure a cache rule.
If you set Type to Directory, note the following:
You can add only one directory at a time. A forward slash (/) matches all directories.
Enter the full path of the directory. The path must start with a forward slash (/). Example: /directory/aaa.
If you set Type to Filename Extension, note the following:
You can enter one or more file extensions. Separate multiple extensions with commas (,). For example,
jpg,txt. The extensions are case-sensitive.The following static file types are supported:
Images: GIF, PNG, BMP, JPEG, and JPG.
Webpages: HTML, HTM, and SHTML.
Audio and video: MP3, WMA, FLV, MP4, WMV, OGG, and AVI.
Text: DOC, DOCX, XLS, XLSX, PPT, PPTX, TXT, and PDF.
Other: ZIP, EXE, TAT, ICO, CSS, JS, SWF, APK, M3U8, TS, EJS, SVG, WOFF, and OTF.
You cannot use an asterisk (*) to match all file types.
Expire In
The cache expiration time for the resources. The maximum value is 3 years. Follow these rules:
For static files that are not frequently updated, such as images and application packages, set the expiration time to one month or longer.
For frequently updated static files, such as JS and CSS files, set the expiration time based on your business needs.
For dynamic files, such as PHP, JSP, and ASP files, set the expiration time to 0s. This disables caching.
Prioritize Origin Server's Cache Policy
If you enable this feature, the cache policy in the response from the origin server takes precedence. This applies if the origin server response includes the Cache-Control or Pragma header.
Ignore No-Cache Headers From Origin
If you enable this feature, DCDN nodes ignore the following no-cache headers in the response from the origin server.
Cache-Control: no-store
Cache-Control: no-cache
Cache-Control: max-age=0
Pragma: no-cache
Client Follows DCDN Cache Policy
If you enable this feature, the DCDN node sends the final effective cache policy to the client.
Force Revalidation
This parameter takes effect only when the cache expiration time is 0. The effects are as follows:
Disabled (default): When the time-to-live for DCDN is set to 0, files are not cached on the DCDN nodes, and an origin fetch is performed for each request.
Enabled: When the time-to-live of DCDN is set to 0, files can be cached on DCDN nodes, and every request must be revalidated with the origin server.
Weight
The priority of the cache rule. The value can be from 1 to 99. A larger value indicates a higher priority. Rules with higher priorities take precedence.
NoteIf you have multiple cache rules, set a different weight for each rule to control their execution priority.
If multiple rules have the same weight, the rule that was created earlier has a higher priority, regardless of the rule type.
If you configure multiple cache policies, DCDN stops matching other policies 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.
After you add a cache rule, it appears in the list on the Cache Duration tab. You can then Modify or Delete the rule as needed.
Alibaba Cloud DCDN default cache rules and priorities
After a DCDN POP retrieves a file from an origin server, the POP processes the file based on the priorities of the following cache rules. A smaller number specifies a higher priority:
If the response carries the
pragma:no-cache,cache-control:no-cache(orno-store, ormax-age=0) directive, DCDN follows the origin's policy and does not cache the resource.DCDN follows the TTL for cached resources, or the TTL for HTTP status codes that are configured in the console.
NoteIf a request to DCDN matches multiple rules, only one rule takes effect. The priority is determined as follows: weight > rule creation time.
If you create multiple cache rules, we recommend that you specify a unique weight for each cache rule to define the priorities of the cache rules. A higher weight specifies a higher priority.
Cache rules that have the same weight are prioritized based on the creation time, regardless of the rule type. The rule that has the earliest creation time takes precedence.
CDN follows other cache rules set on the origin server. Headers in responses from the origin server are in the following descending order of priority:
Cache-Control>Expires>Last-Modified>ETag.The response from the origin server uses the
cache-controlheader to set the expiration time. The directive ismax-ageors-maxage, and the value ofmax-ageors-maxageis greater than 0. For example: cache-control:max-age=3600. If bothmax-ageands-maxageexist, the value ofs-maxageprevails.The response carries the
Expiresheader, such as Expires:Tue, 25 Nov 2031 17:25:43 GMT.If the response carries the
ETagorLast-Modifiedheader, the TTL is calculated based on the following rules:If the response carries the
Last-Modifiedheader, TTL = (Current time -Last-Modified) × 0.1. If the result is from 10 seconds to 3,600 seconds, the result applies. If the result is less than 10 seconds, the TTL is 10 seconds. If the result is greater than 3,600 seconds, the TTL is 3,600 seconds.If the response carries only the
ETagheader, the TTL is 10 seconds.
If the response does not carry the
ETag,Last-Modified,Cache-Control, orExpiresheader, the file is not cached on the POP.
Cache response information
Date:Indicates the time when the origin server responded to the DCDN POP with the resource.
When a DCDN POP revalidates a resource with the origin server using the
If-Modified-Sinceheader orIf-None-Matchheader in the origin fetch request, and the origin server returns a 304 status code, the Date information is updated.The format is GMT. For example:
Sat, 19 Apr 2025 08:58:31 GMT.
X-Cache:Indicates whether the requested resource hit the cache on the DCDN POP. The following table shows the different states and their meaning:
State
Description
HITThe resource cache was hit on the DCDN POP.
MISSThe resource cache was not hit on the DCDN POP, and the resource was provided by the origin server.
X-Swift-Cachetime: Indicates the cache expiration time of the resource on the DCDN POP, measured in seconds.X-Swift-SaveTime:Indicates the time when the resource was first cached on the DCDN L1 POP directly accessed by the client.
The format is 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 the DCDN POP. The layer of POP is determined by the website's cache architecture, which could be L2 or at another cache level.
The format is Unix timestamp. For example:
1745053111, which represents2025-04-19 16:58:31.
HTTP caching mechanisms
HTTP provides three types of headers that can be used to control caching behavior:
Configuration examples
Example 1: To cache .txt files for 7 days, you can add a cache rule in the DCDN console for the `.txt` file extension and set the cache expiration time to 7 days.

Example 2: The following cache policies are configured for the accelerated domain name demo.aliyun.com. When a DCDN node fetches the resource http://demo.aliyun.com/image/example.png from the origin server, the request matches both rules. Because the two rules have the same weight, their priority is determined by the creation time. The rule that was created earlier has a higher priority. In this case, the rule for the `/image` directory was created earlier, so the rule for the directory type takes effect.