Origin Error Caching
  • 19 Jun 2024
  • 3 Minutes to read
  • PDF

Origin Error Caching

  • PDF

Article summary

Overview

The Origin Error Caching rule lets you set conditions for caching specified error response codes from the origin server. A server error (such as a 5xx server error) typically implies a temporary issue that might persist for a certain duration. You can use Origin Error Caching (also known as negative caching) to avoid sending repetitive requests to the origin server during this time, thus reducing the load on the origin server and also providing a quicker response to the client.

Note the following:

  • By default, origin error caching policies in the HTTP response from the origin override the error caching policies defined by the rule.
  • By default, the error caching policies specified by the rule are used ony when there is no error caching policy specified in the response.
  • However, you can select the Origin Override setting so that error caching policies specified by the rule override any headers in the response related to origin error caching.

You can define this rule at the host or the path level.

Warning!

Error code caching (also known as negative caching) permits storing error codes for a specific duration (x amount of seconds).

During the period when error code caching is active, subsequent requests for a particular URL are not sent to the origin. Any end user requesting the URL will automatically receive the cached status code.

The purpose of error code caching is to allow the origin sufficient time to recover before the CDN attempts another request for the same URL.


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 an Origin Error Caching rule:

  1. Navigate to the Select Rule dialog.

  2. In the Select Rule dialog, choose Origin Error Caching.

  3. In the Origin Error Codes field, enter the relevant response code or codes.
    All 4xx and 5xx HTTP status codes are supported.

  4. Set the caching rules.
    Note that the caching rules are separately defined for both the CDN and the client to enable setting distinct error caching behavior.
    The following options are available under both CDN TTL and Client TTL:

    • TTL in Seconds: Used to specify the caching duration. Select TTL in seconds and then specify the caching duration (in seconds).
    • Obey Origin: Follows the TTL parameters defined in the HTTP response from the origin.
    • No Cache: Revalidates with the origin before serving the cached error.
    • No Stores: Sends all requests to the origin. Does not cache errors.
  5. By default, the origin error caching settings are applied only when there is no error caching policy specified in the response from the origin server. To override the default, select Origin CDN/Client Override.

    When this parameter is set, if the response contains headers from the origin specifying error caching, the rule settings will override them.

  6. Select Add Rule.




Example
In the following example, the rule is configured so that when a request to the origin returns an error specified by the rule (any 5xx error), the CDN caches the error response for the amount of time specified by the rule (2 seconds). During that time, if a subsequent request for the same content is received, the CDN serves the cached error response instead of forwarding the request to the origin server. Note that the Origin CDN Override option is toggled on. The Client TTL is not configured, so any origin caching policies defined by the origin are used.

originErrorCachingExample3.png

SVTA Component: MI.NegativeCachePolicy

When you save the configuration version, the MI.NegativeCachePolicy component is added to the JSON configuration.

This example configures the following error caching (negative cache) policies for error-codes 400 and 500:

{
	"generic-metadata-type": "MI.NegativeCachePolicy",
	"generic-metadata-value": {
		"cache-policy": {
			"internal": "4",
			"external": "as-is",
			"force-internal": true,
			"force-external": false
		},
		"error-codes": [
			"400",
			"500"
		]
	}
}

Note that "internal" represents the CDN error caching behavior, while "external" represents the client error caching behavior.

  • "internal": "4"- These errors will be cached for 4 seconds.
  • "force-internal": true - The CDN error caching settings override any error caching settings in the origin response.
  • "force-external": false; "external": "as-is" - No client error caching behavior is specified.

Was this article helpful?

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.