- 19 Jun 2024
- 1 Minute to read
- Print
- PDF
Serve Stale
- Updated on 19 Jun 2024
- 1 Minute to read
- Print
- PDF
Overview
TTL (time-to-live) specifies the amount of time a content item in the CDN cache is considered valid. When the TTL expires, an object is considered stale. Stale content is typically fetched from the origin. However you may decide that under certain conditions, it would be beneficial to serve stale content instead.
The Serve Stale rule can be used to instruct the CDN to serve stale objects under these conditions:
When the origin server is temporarily unable to serve the content, as indicated by specifying any of the following origin errors: (500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout).
During the revalidation of content against the origin.
The decision to serve stale content should be considered carefully, and with regards to the nature of the content.
You can define this rule at the host level, and then define this rule at the path level for exceptions.
Configure the Rule
Here, we'll describe how to configure the rule with the Delivery Service Management UI.
API Users may choose to build the site configuration offline.
To configure a Serve Stale rule:
In the Select Rule dialog, choose Serve Stale.
Establish the Serve Stale conditions.
- Specify error codes to instruct the CDN to serve content in response to specific origin errors, instead of displaying the error itself.
In the If Error field, enter the error (or multiple errors separated by commas), and press Enter.
The following codes are supported: 500, 502, 503, 504.
{height="" width=""} - Set the Revalidation Condition to instruct the CDN to serve stale content while the CDN is revalidating with the origin.
Toggle on Serve stale content while revalidating.
- Specify error codes to instruct the CDN to serve content in response to specific origin errors, instead of displaying the error itself.
Choose Add Rule.
SVTA Component: MI.StaleContentCachePolicy
When you save the configuration version, the MI.StaleContentCachePolicy component is added to the JSON configuration.
In this example, stale content will be served when the origin server returns a 500 or 502 code, and during revalidation of content against the origin.
{
"generic-metadata-type": "MI.StaleContentCachePolicy",
"generic-metadata-value": {
"stale-if-error": [
"500","502"
],
"stale-while-revalidating": true
}
Field | Valid Values |
---|---|
stale-if-error | 500, 502, 503, 504 |
stale-while-revalidating | true, false |