---
title: "Decide how stale a cache may be · Agent Wranglers"
url: https://agentwranglers.se/playbook/scaling/caching/cache-freshness
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Decide how stale a cache may be

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). Updated 2026-10-21.

- ID: SCL-35
- Level: Recommended
- Chapter: [Caching](https://agentwranglers.se/playbook/scaling/caching)
- Rule: Give every cached value an expiry or an invalidation rule, chosen for how stale it may safely be.
- How: Prefer short expiry times for data that changes, and delete the cache entry right after the write commits, in the same code path. Keep the expiry even then, so a missed delete heals itself. Never cache permissions, prices at checkout or anything that must be exact at the moment of use. Include the user or tenant in the cache key for private data. For HTTP responses, [Cache files for a year and pages briefly](https://agentwranglers.se/playbook/website/performance/cache-control) sets the times.
- Check: Change a cached value through the app. The next read shows the new value, or the stale one only within its stated expiry.

## 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.

### JavaScript example

```js
await db.none('UPDATE products SET price_cents = $1 WHERE id = $2', [price, id]);
await cache.del(`product:${id}`);
```

### Python example

```python
cursor.execute("UPDATE products SET price_cents = %s WHERE id = %s", (price, product_id))
cache.delete(f"product:{product_id}")
```

## Related rules

- [Read from replicas only what may lag](https://agentwranglers.se/playbook/data/caches-and-copies/replica-lag) in Data
- [Cache whole answers for repeated inputs](https://agentwranglers.se/playbook/ai-features/latency-cost-and-fallbacks/answer-cache) in AI features
- [Refresh every view a change touches](https://agentwranglers.se/playbook/app-ui/client-and-server-state/refresh-after-change) in App interface
- [Use Redis 8 or Valkey for caches and queues](https://agentwranglers.se/playbook/stack/databases-and-storage/redis-or-valkey) in Software choices
- [Cache what is read often and costly to build](https://agentwranglers.se/playbook/scaling/caching/cache-hot-reads) in Scaling
- [Cache files for a year and pages briefly](https://agentwranglers.se/playbook/website/performance/cache-control) 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/cache-freshness">Agent Wranglers scaling playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Keep the app working when the cache is gone](https://agentwranglers.se/playbook/scaling/caching/survive-cache-loss)
- [Caching](https://agentwranglers.se/playbook/scaling/caching)
