Serve Stale
  • 19 Jun 2024
  • 1 Minute to read
  • PDF

Serve Stale

  • PDF

Article summary

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:

  1. Navigate to the Select Rule dialog.

  2. In the Select Rule dialog, choose Serve Stale.

  3. 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.

      serveStale1.png{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.

    serveStale2.png

  4. 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
}



FieldValid Values
stale-if-error500, 502, 503, 504
stale-while-revalidatingtrue, false

Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.