Stale-If-Error Caching
Stale-if-error is a Cache-Control directive that allows a cache to serve an expired response when the origin returns an error or is unreachable. Instead of showing users a failure, the app receives the last known good data for a defined grace period.
Technical Architecture & Deep-Dive
Third-party APIs experience outages and rate-limit errors. If an app depends on them for catalog, pricing, or configuration data, an outage can break the entire experience.
With `stale-if-error=86400`, an edge cache can keep serving yesterday data while the upstream recovers. Paired with stale-while-revalidate, it makes cached endpoints both fast and resilient.
Key Architectural Benefits
Implement Stale-If-Error Caching at the Edge
Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.
Frequently Asked Questions
Q:Is stale-if-error safe for all data?
No. It suits data where slightly outdated values are acceptable, like catalogs or content. Avoid it for balances, inventory holds, or security decisions.
Related Architecture Concepts
Stale-While-Revalidate (SWR) is an HTTP cache control extension that instructs the edge to serve an existing cached (stale) response instantly to the client, while asynchronously initiating a background fetch to refresh the cache. Users experience zero latency wait time while always receiving fresh data.
Graceful degradation is designing systems to keep providing core functionality when some components fail. For aggregated APIs, it means returning the data that succeeded, with optional sections omitted or replaced by cached values, rather than failing the entire response.
Cache-Control is an HTTP response header that tells browsers, CDNs, and proxies whether and how long a response may be cached. Directives such as max-age, s-maxage, private, no-store, and stale-while-revalidate control freshness and sharing for every cached copy.
Ready-to-Use Edge Recipes
REST API rate limits hit fast from Frontend / Web. Cache 300s on GET calls where the query string scopes the response.
Ticket counts cached with 60s TTL for status subdomain. For "cache zendesk api for customer status page", store ZENDESK_API_TOKEN in Secret Vault, call https://{{secrets.ZENDESK_SUBDOMAIN}}.zendesk.com/api/v2/tickets.json from a Worker, and let Webflow hit only https://realcomposer.com/v1/workspace/cache-zendesk-api-status-page with an rc_live_ client token. Enable 60s GET cache only when query params identify the resource.