All Products
Search
Document Center

Edge Security Acceleration:Configure cache expiration for status codes

Last Updated:Sep 21, 2026

When a DCDN node fetches a resource from the origin server, the origin server returns a response status code. You can configure a cache duration for status codes in Alibaba Cloud DCDN. When a client requests the same resource again, DCDN returns the status code directly without triggering an origin fetch, which reduces the load on the origin server. When the configured cache duration expires, an origin fetch is triggered again.

Note

Note: When this feature uses rule conditions from the Rules Engine, execution order follows the Rules Engine priority, NOT this feature's own priority.

Use cases

Use this feature to control how DCDN nodes cache responses when your origin server returns non-2xx status codes.

By default, DCDN processes 2xx responses based on the default cache rules and priorities of Alibaba Cloud CDN and DCDN. If your origin frequently returns non-2xx status codes, you can set a TTL for these codes so DCDN nodes return cached responses directly, reducing origin load.

Example

A file is deleted from the origin server, but clients continue to request it. Each request triggers an origin fetch that returns a 4xx code, increasing origin load. If you cache 4xx status codes, the DCDN node caches the 4xx response after the first fetch. Subsequent requests within the cache duration receive the cached 4xx response directly.

Cache rules for abnormal status codes

  • For the 204, 301, 305, 404, 405, 414, 424, 429, 500, 501, 502, 503, and 504 status codes, the cache rules are as follows:image

    1. If the origin server returns the set-cookie response header, DCDN does not cache the response.

    2. If the origin server does not return the Set-Cookie response header, the response is cached based on the status code TTL that is configured in the DCDN console. If multiple rules are configured, see Priority of multiple rules for how the effective rule is determined.

    3. If the origin server does not return the Set-Cookie response header and no status code TTL is configured in the DCDN console, the response is cached based on the Pragma, Cache-Control, or Expires response header that is set by the origin server.

    4. If the origin server does not return the Set-Cookie, Pragma, Cache-Control, or Expires response header and no status code TTL is configured in the DCDN console, the response is cached for 1 second by default.

  • For the 302, 307, and 403 status codes, the cache rules are as follows:image

    1. If the origin server returns the set-cookie response header, DCDN does not cache the response.

    2. If the origin server does not return the Set-Cookie response header, the response is cached based on the status code TTL that is configured in the DCDN console. If multiple rules are configured, see Priority of multiple rules for how the effective rule is determined.

    3. If the origin server does not return the Set-Cookie response header and no status code TTL is configured in the DCDN console, the response is cached based on the Pragma, Cache-Control, or Expires response header that is set by the origin server.

    4. If the origin server does not return the Set-Cookie, Pragma, Cache-Control, or Expires response header and no status code TTL is configured in the DCDN console, the response is not cached.

  • For the 304 status code, DCDN does not cache the response, and the cache duration cannot be configured in any way.

  • For other abnormal status codes, such as the 400 status code, the cache rules are as follows:

    1. If the origin server returns the set-cookie response header, DCDN does not cache the response.

    2. If the origin server does not return the Set-Cookie response header, the response is cached based on the status code TTL that is configured in the DCDN console. If multiple rules are configured, see Priority of multiple rules for how the effective rule is determined.

    3. In other scenarios, the response is not cached.

  • For requests that use range origin fetch, if a DCDN node receives a non-206 status code from the origin server, the DCDN node deletes the cached slices (an origin fetch timeout does not cause cached files to be deleted).

    In a range origin fetch, the origin server splits a large file into multiple smaller slices and returns them to DCDN nodes. For example, a file is split into 10 slices and a DCDN node has cached five slices. When the node requests the sixth slice, the origin server returns a 5xx status code. In this case, all five slices that were previously cached are deleted.

Rule priority

When a request matches multiple cache rules, only one takes effect:

  • Evaluation order:

    Rules are evaluated first by type (File Extension > Directory), and then by creation time (older > newer).

  • Priority for rules of different types: File Extension > Directory.

    For example, if a user request matches two rules (both configured for the 404 status code) of the File Extension and Directory types, the expiration time for the 404 status code is determined by the File Extension rule. For a detailed example, see Configuration examples.

  • Priority for rules of the same type: Older > Newer (from top to bottom in the rule list).

    For example, if a user request matches two rules (both configured for the 404 status code) of the same type (both File Extension or both Directory), the expiration time for the 404 status code is determined by the rule that was created first. For a detailed example, see Configuration examples.

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 in the Actions column.

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

  5. Click the Status Codes and Expiration Time tab.

  6. Click Add to create a cache rule for status codes.

    image

    Type

    Notes

    Type

    Select a type: Directory or File Extension.

    Note

    Priority for rules of different types: File Extension > Directory. For more information, see Rule priority.

    Object

    • If you select Directory:

      • You can add only one directory at a time.

      • Enter the full directory path starting with /, for example, /directory/aaa.

    • If you select File Extension:

      • Enter file extensions separated by commas, for example, jpg,txt.

        Note

        File extensions are case-sensitive. If you create rules for the same extensions in different cases (for example, jpg,txt and jpg,txt), the later rule overwrites the jpg,txt rule. Create separate rules for txt and jpg to avoid this.

      • You cannot use an asterisk (*) to match all file types.

    HTTP Status Codes and Expiration Time

    Specify the status codes to cache and their TTL in seconds (maximum: 3 years):

    • Separate multiple status codes with commas (,).

    • 2xx and 3xx codes: individual codes only. For example, 201=10 is valid, but 2xx=12 is not.

    • 4xx and 5xx codes: both individual codes and wildcards are supported. For example, 401=10 and 4xx=12 are both valid.

    Honor Origin TTL

    When enabled, origin server cache headers (Cache-Control, Pragma) take precedence over the configured TTL.

    Ignore Origin No-Cache Header

    When enabled, DCDN nodes ignore these origin no-cache headers:

    • Cache-Control: no-store

    • Cache-Control: no-cache

    • Cache-Control: max-age=0

    • Pragma: no-cache

    Follow POP TTL

    When enabled, the DCDN node sends the final effective cache policy to the client.

    Force Revalidation

    Takes effect only when the cache TTL is set to 0:

    • Disabled (default): When DCDN TTL is 0, files are not cached on DCDN nodes. Every request triggers an origin fetch.

    • Enabled: When DCDN TTL is 0, files are cached on DCDN nodes, but every request triggers an origin fetch to revalidate.

  7. Click OK.

    The new rule appears in the Status Codes and Expiration Time list, where you can Modify or Delete it.

Configuration examples

  • Example 1: Directory type rule

    Create a Directory rule as shown below:Example 1

    For the /directory/aaa directory, all 4xx codes are cached for 10 seconds and the 201 code for 15 seconds. Within the TTL, DCDN responds directly. After expiration, requests are forwarded to the origin.

  • Example 2: File extension type rule

    Create a File Extension rule as shown below:Example 2

    For .jpg and .txt files, the 403 code is cached for 10 seconds and the 404 code for 15 seconds. Within the TTL, DCDN responds directly. After expiration, requests are forwarded to the origin.

  • Example 3: Priority for rules of different types

    A Directory rule and a File Extension rule with different TTL values are created as shown below:Example 3

    A client requests http://example.com/directory/aaa/test.jpg. The DCDN node fetches the resource from the origin, which returns 404. This request matches both the Directory rule and the File Extension rule. Because File Extension > Directory, the File Extension rule applies and the 404 is cached for 20 seconds.

  • Example 4: Priority for multiple rules of the same type

    Directory rule 1 is created first for /directory, then Directory rule 2 for /directory/aaa, with different TTL values as shown below:Example 4

    A client requests http://example.com/directory/aaa/test.jpg. The origin returns 404, which matches both Directory rules. Because Older > Newer, Directory rule 1 applies and the 404 is cached for 15 seconds.

Related API operations

Add domain names in batches