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 image abc.jpg has been deleted from the origin server and is not cached on CDN PoPs, CDN pulls it for each request, but the origin server returns a 4xx status code each time. This increases 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
- If a resource is not cached on CDN PoPs, the status code generated when a client requests the resource cannot be cached even if a cache TTL has been set for this status code.
- The status code cache TTL cannot be configured for domain names with special configurations.
- If the service type of your domain name is whole site acceleration, this function takes effect only for static resources.
- By default, CDN caches status codes 404, 500, 502, and 504 for 3 seconds and does not cache other status codes.
- The header settings determine whether the 404 status code is cached by default. If the X-HTTP-Method-Override, X-HTTP-Method, or X-Method-Override header is carried, the 404 status code is not cached by default. If not, the 404 status code is cached for 3 seconds.
- When Query Parameters is set to Ignore all for a resource, and a status code (for example, 400) returned for a client request is cached, the status code (400 in this example) will be returned for all requests for the resource within the cache TTL.
- You can modify the cache TTL of the following status codes:
- 4XX: 400, 401, 403, 404, 405, 407, 414, 416, and 451
- 5XX: 500, 501, 502, 503, 504, 509, and 514
- 3XX: 301 and 302
Procedure
- Log in to Huawei Cloud console. Choose .
The CDN console is displayed.
- In the navigation pane, choose .
- In the domain list, click the target domain name or click Configure in the Operation column.
- Click the Cache Settings tab.
- 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 value ranges from 0 to 365 days.
NOTE:
Status codes 3XX and 416 can be cached for 0 to 20 seconds.
3 days
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot