The Serve Stale Content feature is a key tool for fault tolerance and availability in Alibaba Cloud CDN. It primarily serves expired static content from CDN nodes when an origin server has an error, such as a timeout or when it returns a 4xx or 5xx status code. This approach improves availability and user experience by maintaining access to your website during temporary origin server outages. This feature does not apply to dynamic resources.
Use cases
Origin server failure or unavailability: When an origin server fails or becomes unavailable due to issues such as server downtime, network interruptions, or application errors, CDN nodes cannot fetch the latest content from the origin server.
-
If the Serve Stale Content feature is disabled, CDN nodes attempt an origin fetch when they receive a user request. If an origin error occurs, the fetch fails, and users cannot access the website.
-
If the Serve Stale Content feature is enabled, CDN nodes can serve expired content from their cache during an origin error. This ensures website accessibility.
How it works
Procedure
-
Log on to the CDN console.
-
In the navigation pane on the left, click Domain Names.
-
On the Domain Names page, find the domain name that you want to manage, and click Manage in the Actions column.
-
In the navigation pane on the left for the domain, click Cache.
-
Click the Serve Stale Content tab, and then click Configure.
Parameter
Required
Default
Description
Honor Origin
Optional
Disabled. By default, the extended expiration time is determined by the Extended Expiration Time setting.
If you enable this parameter and the origin server response includes the
Cache-Control: stale-if-error=xxheader, Alibaba Cloud CDN uses the value from thestale-if-errordirective as the extended expiration time.Origin Exception Status Code
Optional
By default, an origin error is defined as an origin fetch timeout or a 5xx status code from the origin server.
Use wildcards like
4xxand5xx, or specify exact codes like502and504.You can enter multiple status codes. Separate them with commas.
Extended Expiration Time
Optional
3,600 seconds (1 hour)
The maximum time to serve a stale object from the cache after its TTL expires. The minimum value is 1 second.
-
Click OK.
FAQ
Status code TTL vs. Serve Stale Content
Status code TTL and Serve Stale Content are both cache optimization features provided by Alibaba Cloud CDN, but they have different triggers, cached content, purposes, and configuration methods. The status code TTL feature is primarily used to cache responses with specific status codes to reduce requests to the origin server. In contrast, the Serve Stale Content feature is used to serve expired content during an origin error to improve availability. Depending on your business requirements, you can select the appropriate feature to optimize your website's performance and user experience.
|
Difference |
Status Code TTL |
Serve Stale Content |
|
Trigger |
This feature is triggered when the origin server returns a response with a specific HTTP status code. |
This feature is triggered when the origin server fails, times out, or returns a specific error status code. |
|
Cached content |
Caches the response for a specific status code from the origin server, such as a 404 page. |
Uses expired content that is already stored on Alibaba Cloud CDN nodes. This can be any type of resource. |
|
Purpose |
To reduce origin server load and improve response speed. |
To improve website availability and user experience by serving stale content during an origin error. |
|
Configuration method |
Configured in the Alibaba Cloud CDN cache settings for specific HTTP status codes. |
Configured by enabling the feature and setting an extended expiration time. |
In summary, we recommend configuring the Serve Stale Content feature for origin errors, such as origin fetch timeouts or 5xx/4xx status codes. This feature is ideal for improving availability and user experience during origin outages. By contrast, the status code TTL feature is better for caching specific status codes like 404 or 500 to improve response speed and reduce origin load, but its role during origin errors is limited. You can configure these features individually or together for optimal performance and availability.
However, you must set appropriate cache durations and rules based on your business requirements and website architecture. An excessively long cache duration can prevent users from receiving the latest content, while a duration that is too short may not effectively reduce origin server load.