liveBook · Manning

Proxy_cache_use_stale

As explained in Learn Docker in a Month of Lunches, Second Edition

proxy_cache_use_stale is an NGINX configuration setting that permits serving cached responses when they are stale and specified upstream conditions occur.

proxy_cache_use_stale lets NGINX serve an expired cached response when the upstream application cannot provide a response. This can keep an app partly available during transient failures, rollbacks, or stopped containers. section 20.3

Configure the setting inside the cached location and name the upstream conditions that permit stale content:

  • Use a long-lived cache for content that can remain available during an outage. section 20.3
  • Choose paths carefully: cached pages may remain usable while dynamic API responses become unavailable. section 20.3

Cached web content during an outage

A web location can use `proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;`. After requests populate the cache, removing the web containers still allows the site to respond. An API cache without this setting returns HTTP 502 after its one-minute cache expires.

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Defines the directive, lists supported failure conditions, and demonstrates outage behavior without exploring broader NGINX internals.
Examples
Demonstrates cached web pages surviving container removal while an expired API cache produces HTTP 502.
What it assumes
Assumes basic NGINX location, upstream, cache, and container-operation knowledge while explaining stale-cache behavior practically.
What you can do after
Operate/configure NGINX to preserve selected cached responses during upstream errors and verify behavior with curl.
How it connects
Connects reverse proxying, HTTP caching, upstream availability, cache expiration, and application rollbacks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.