---
title: "Cache public pages at the edge for a few · Agent Wranglers"
url: https://agentwranglers.se/playbook/scaling/caching/edge-micro-cache
id: SCL-43
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 965
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Cache public pages at the edge for a few seconds

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Caching](https://agentwranglers.se/playbook/scaling/caching.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: SCL-43
- Level: Recommended
- Chapter: [Caching](https://agentwranglers.se/playbook/scaling/caching.md)
- Rule: Let the content delivery network or proxy keep public pages that change often, such as a product list, for 1 to 10 seconds with `s-maxage`. Collapse parallel misses into one request to the app.
- Check: Send 1,000 requests for one public page within 5 seconds through the edge. The app's access log shows at most 2 requests for that page. A request with a session cookie for a signed-in page reaches the app every time.
- How: A page that changes every minute still gets thousands of identical requests in that minute. A shared cache that keeps it for 5 seconds sends the app at most one request per page every 5 seconds, whatever the traffic. Set `Cache-Control: public, max-age=0, s-maxage=5, stale-while-revalidate=30`, so browsers ask again and the shared cache answers. Turn on request collapsing, such as `proxy_cache_lock` in nginx, so the first miss fetches the page and the rest wait for it. Only pages that are the same for every visitor qualify. Never cache a signed-in page in a shared cache, as [Keep private pages out of shared caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/private-responses-uncached.md) says. Longer lifetimes for files are in [Cache files for a year and pages briefly](https://agentwranglers.se/playbook/website/performance/cache-control.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### nginx example

```nginx
proxy_cache_path /var/cache/nginx keys_zone=pages:10m max_size=1g;

location /products {
    proxy_cache pages;
    proxy_cache_lock on;
    proxy_cache_use_stale updating error timeout;
    proxy_cache_bypass $cookie_session;
    proxy_no_cache $cookie_session;
    proxy_pass http://shop_app;
}
```

### JavaScript example

```js
app.get('/products', async (req, res) => {
  res.set('Cache-Control', 'public, max-age=0, s-maxage=5, stale-while-revalidate=30');
  res.json(await listProducts());
});
```

### Python example

```python
@app.get("/products")
def products(response: Response):
    response.headers["Cache-Control"] = "public, max-age=0, s-maxage=5, stale-while-revalidate=30"
    return list_products()
```

## Sources

- [RFC 9111 section 5.2.2.10 s-maxage](https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.10)
- [nginx proxy module, proxy_cache_lock](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_lock)

## Related rules

- APS-46 [Keep private pages out of shared caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/private-responses-uncached.md) in Application security
- WEB-42 [Cache files for a year and pages briefly](https://agentwranglers.se/playbook/website/performance/cache-control.md) in Website

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/scaling/caching/edge-micro-cache">Agent Wranglers scaling playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Spread the reads of one hot cache key](https://agentwranglers.se/playbook/scaling/caching/hot-cache-keys.md)
- [Caching](https://agentwranglers.se/playbook/scaling/caching.md)
