liveBook · Manning

Stale data

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

A stale cache is cached content whose configured freshness lifetime has expired.

A stale cache contains content whose configured freshness lifetime has expired. Nginx can still serve that content when the upstream application fails, times out, returns invalid headers, or produces selected HTTP errors. section 20.3

Different lifetimes for web pages and API responses

Configure web responses to remain cached for six hours and permit stale delivery during upstream failures. Configure API responses to expire after one minute without stale delivery; after the API container stops, Nginx returns HTTP 502. section 20.3

Listing 20.3 Nginx as a caching reverse proxy for HTTP content
    ...
    location = /api/image {
        proxy_pass             http:/./iotd/image;
        proxy_set_header       Host $host;
        proxy_cache            SHORT;
        proxy_cache_valid      200  1m;
        ...
    }
    location / {
        proxy_pass             http:/./image-gallery;
        proxy_set_header       Host $host;
        proxy_cache            LONG;
        proxy_cache_valid      200  6h;
        proxy_cache_use_stale  error timeout invalid_header updating
                               http_500 http_502 http_503 http_504;
        ...
    }

Inspect the Nginx locations that define cache lifetimes and the errors allowed to trigger stale responses. section 20.3

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

How deep it goes
Explains expiration and failure-triggered delivery through Nginx directives, but stops short of broader cache validation internals.
Examples
Contrasts six-hour web caching with one-minute API caching after web and API containers are removed.
What it assumes
Assumes basic familiarity with Nginx, Docker containers, HTTP requests, and upstream application components.
What you can do after
Operate/configure Nginx to choose cache lifetimes and permit stale responses for selected upstream failures.
How it connects
Connects caching with reverse proxies, upstream failures, HTTP status codes, and application reliability.

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.