All Products
Search
Document Center

Edge Security Acceleration:Configure cache expiration time

Last Updated:Oct 10, 2025

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

  1. Log on to the DCDN console.

  2. In the left-side navigation pane, click Domain Names.

  3. On the Domain Names page, find the domain name that you want to manage and click Configure.

  4. In the left-side navigation tree of the domain name, click Caching.

  5. On the Cache Duration tab, click Add.

  6. In the Cache Duration dialog box, configure a cache rule.

    image

    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.

    Note
    • If 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.

  7. 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:缓存优先级

  1. If the response carries the pragma:no-cache, cache-control:no-cache (or no-store, or max-age=0) directive, DCDN follows the origin's policy and does not cache the resource.

  2. DCDN follows the TTL for cached resources, or the TTL for HTTP status codes that are configured in the console.

    Note

    If 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.

  3. 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.

    1. The response from the origin server uses the cache-control header to set the expiration time. The directive is max-age or s-maxage, and the value of max-age or s-maxage is greater than 0. For example: cache-control:max-age=3600. If both max-age and s-maxage exist, the value of s-maxage prevails.

    2. The response carries the Expires header, such as Expires:Tue, 25 Nov 2031 17:25:43 GMT.

    3. If the response carries the ETag or Last-Modified header, the TTL is calculated based on the following rules:

      1. If the response carries the Last-Modified header, 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.

      2. If the response carries only the ETag header, the TTL is 10 seconds.

  4. If the response does not carry the ETag, Last-Modified, Cache-Control, or Expires header, 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-Since header or If-None-Match header 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

    HIT

    The resource cache was hit on the DCDN POP.

    MISS

    The 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 represents 2025-04-19 16:58:31.

HTTP caching mechanisms

HTTP provides three types of headers that can be used to control caching behavior:

  1. Expiration time validation mechanism

    When a client requests resources from a server, the client and server define the TTL of the returned resources that are cached on the POPs. The resources expire when the TTL ends.

    HTTP provides the following types of headers that can be used to define the cache TTL:

    Header

    Protocol version

    Function

    Example

    Type

    Pragma

    HTTP/1.0

    The Pragma header specifies whether a resource is cached. If Pragma is set to no-cache, the resource is not cached. Pragma is compatible with servers that use only HTTP/1.0.

    Pragma:no-cache

    Request and response

    Expires

    HTTP/1.0

    The Expires header specifies a date and point in time. Cached resources expire at the specified point in time.

    If Expires is set to an invalid value, such as 0, the resource has expired.

    Expires: Wed, 21 Oct 2022 07:28:00 GMT

    Response

    Cache-Control

    HTTP/1.1

    The Cache-Control header holds different directives that specify caching policies. Mainstream clients, such as browsers, use the Cache-Control header to control caching behavior.

    The following directives specify that files are not cached:

    • Cache-Control:no-cache

    • Cache-Control:no-store

    • Cache-Control:max-age=0

    The following directive specifies that files are cached for 1 hour: Cache-Control:max-age=3600

    Request and response

  2. Resource tags

    The first time a client requests a resource from a server, the server adds a tag to the response headers. The tag is used to identify the requested resource when the client requests the same resource again. The header of subsequent requests carries this tag. If the server checks this tag and confirms that the requested resource is not updated, the HTTP 304 status code is returned to the client. The client retrieves the resource from the local cache. If the server detects that the tag is different from that of the resource on the server, the server informs the clients that the resource is updated or has expired. In this case, the client must retrieve the latest version of the resource from the server.

    HTTP provides the following types of headers that can be used to control cache versions:

    Header

    Protocol version

    Description

    Example

    Type

    Last-Modified

    HTTP/1.0

    Last-Modified specifies the time when a resource was last updated.

    Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT

    Response

    ETag

    HTTP/1.1

    The ETag header is the unique identifier of each version of a resource.

    ETag specifies whether a resource is updated. If the resource is updated, the server does not need to return a complete response.

    ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"

    Response

  3. Multi-Replica Negotiation Mechanism

    Caching software uses keywords to index objects on disks. In HTTP/1.0, URLs are used as keywords. However, different resources may point to the same URL. To differentiate the resources, clients must provide additional information, such as the Accept-Language and Accept-Charset headers. HTTP/1.1 introduced the Vary response header to implement content negotiation. The Vary header lists the request headers that must be included to implement content negotiation.

    In content negotiation, the Vary header is used to differentiate variants. This way, the clients can retrieve the desired variants:

    Header

    Protocol version

    Description

    Example

    Type

    Vary

    HTTP/1.1

    Examples:

    • The server uses Vary: Accept-Encoding to inform the recipient, such as a DCDN POP, that the requested resource has two variants (compressed and uncompressed). When the client sends requests to DCDN for the same resource, older browsers receive the uncompressed resource (to avoid compatibility issues), while newer browsers receive the compressed resource (to reduce data transfer traffic).

    • The server uses Vary: User-Agent to identify the type of the browser that sends the request, and informs the recipient, such as a DCDN POP, to cache different versions of the resource based on the browser type.

    Vary: Accept-Encoding

    Vary: Accept-Encoding,User-Agent

    Response

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.

image.png

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.image.png

Related API operations

Batch-configure domain names