---
title: "Decide how stale a cache may be · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/caches-and-copies/cache-freshness
updated: 2026-10-20
licence: "All rights reserved"
---

# Decide how stale a cache may be

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Caches and copies](https://agentwranglers.se/playbook/data/caches-and-copies)
- 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.
- Check: Change a cached value through the app. The next read shows the new value, or the stale one only within its stated expiry.

Example:

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

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

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/caches-and-copies/cache-freshness`.

- Previous: [Name the source of truth](https://agentwranglers.se/playbook/data/caches-and-copies/source-of-truth)
- Next: [Read from replicas only what may lag](https://agentwranglers.se/playbook/data/caches-and-copies/replica-lag)
- [Caches and copies](https://agentwranglers.se/playbook/data/caches-and-copies)
