Updated on 2024-01-26 GMT+08:00

Status Code Cache TTL

When a CDN PoP pulls a resource from the origin server, the origin server returns a status code. You can set the cache time to live (TTL) of the status code on the CDN console. When a client requests the resource again, origin pull will not be triggered, reducing the origin pull ratio and the pressure on the origin server.

Scenarios

This function applies to the scenario where the origin server returns an abnormal status code. When the origin server is running properly, CDN caches an origin resource on PoPs based on cache rules you configure. When a user accesses the resource, origin pull will not be triggered. If the origin server responds abnormally and you do not want the origin server to respond to all requests, you can set the status code cache TTL to reduce the pressure on the origin server.

  • Application: If users are continuously accessing image abc.jpg that is not cached on CDN PoPs and that has been deleted from the origin server, CDN PoPs will pull the image for each user request and the origin server will return a 4xx status code, increasing the pressure on the origin server. In this case, if you configure the cache TTL for the status code 4xx on CDN, CDN PoPs will directly return the status code 4xx when users request the image, and origin pull is not required.

Precautions

  • The status code cache TTL cannot be configured for domain names with special configurations.
  • Domain names whose service type is whole site acceleration do not support this function.
  • By default, CDN caches status codes 400, 404, 416, 500, 502, and 504 for 3 seconds and does not cache other status codes.
  • You can modify the cache TTL of the following status codes:
    • 4XX: 400, 403, 404, 405, and 414
    • 5XX: 500, 501, 502, 503, and 504
    • 3XX: 301 and 302

Procedure

  1. Log in to Huawei Cloud console. Choose Service List > Content Delivery & Edge Computing > Content Delivery Network.

    The CDN console is displayed.

  2. In the navigation pane, choose Domains.
  3. In the domain list, click the target domain name or click Configure in the Operation column.
  4. Click the Cache Settings tab.
  5. Click Add under Status Code Cache TTL.
    Figure 1 Adding a status code cache TTL
    Table 1 Parameters

    Parameter

    Description

    Example

    Status Code

    Status code to be cached.

    404

    Cache TTL

    Duration for caching the status codes on CDN PoPs.

    • If it is set to 0, the status code is not cached.
    • The maximum value is 365 days.

    3 days

  6. Configure the parameters and click OK.

Example

Assume that you have configured the following status code cache rules for the domain name www.example.com.

Result: When a user accesses a resource that is not cached on a CDN PoP, the CDN PoP pulls the resources from the origin server. However, the origin server has deleted the resource and returns a status code 404. CDN transparently transmits the status code to the user and caches the status code on the CDN PoP. Within the cache TTL (30 days), when a user accesses the resource again, CDN directly returns the status code 404 to the user and does not need to pull content from the origin server, reducing the pressure on the origin server.