| Version: v2023-09-20 | Includes use: Yes | 
|---|
Behavior name: Cache HTTP Error Responses
Caches the origin's error responses to decrease server load. Applies for 10 seconds by default to the following HTTP codes:
- 204
- 305
- 404
- 405
- 501
- 502
- 503
- 504
505Note: This behavior no longer caches
400error responses from the origin server. If you need to cache such errors, you can set up a custom variable. See Caching400responses for more information.
Default behavior
These samples reflect the behavior's default settings. You can use these as is in your configurations or make adjustments based on the behavior's available options.
data "akamai_property_rules_builder" "cache_error" {
  rules_v2023_09_20 {
    name     = "Cache HTTP Error Responses"
    comments = "Caches the origin's error responses to decrease server load."
    behavior {
      cache_error {
        enabled        = true
        ttl            = "10s"
        preserve_stale = true
      }
    }
  }
}
{
  "name": "cacheError",
  "options": {
    "enabled": true,
    "ttl": "10s",
    "preserveStale": true
  }
}
Options
| Option | Description | 
|---|---|
| enabled | Activates the error-caching behavior.
         | 
| ttl | Overrides the default caching duration of  10s. Note that if set to0it is equivalent tono-cachewhich forces revalidation and may cause a traffic spike. This can be counterproductive when, for example, the origin is producing an error code of500. | 
| preserve_stale | When enabled, the edge server preserves stale cached objects when the origin returns  500,502,503, and504error codes. This avoids re-fetching and re-caching content after transient errors. | 
