What to give
- Language and framework: [e.g. Node.js with Express, Python with Django, PHP with Laravel]
- Cache available: [e.g. Redis, Memcached, in-process memory, CDN]
- Slow reads: [paste the queries or calls, how often each runs, how long each takes]
- How the data changes: [e.g. product prices edited by admins a few times a day, stock changes on every order]
- How stale data may be: [e.g. prices must be live, blog lists can be 10 minutes old]
- Per-user or shared data: [which reads depend on the signed-in user]
Task
Decide what to cache and write the caching code for it.
Design checklist
- Cache only reads that repeat and cost real time; leave fast or unique reads alone.
- Key format with a prefix, a version and every parameter that changes the result, such as product:v2:{id}:{currency}.
- Expiry per entry, matched to how stale the data may be.
- Invalidation: which writes delete or update which keys, written next to the write code.
- Stampede guard for hot keys: a short lock or early refresh so one request rebuilds the entry, not hundreds.
- Per-user data kept under user-scoped keys, never served to another user.
- Behaviour when the cache is down: fall back to the database, with a timeout.
- Metrics: hit rate, miss rate and rebuild time.
Output format
- | Read | Cache it? | Key format | Expiry | Cleared by |
- A read-through helper in the language given, with comments.
- The invalidation calls added to each write path.
- | Risk | Guard |, covering stale data, stampedes, memory growth and leaking private data.
Guardrails
- Never cache responses that contain secrets, tokens or another user's personal data under a shared key.
- Do not cache error responses for the normal expiry; use a much shorter one or none.
- State any assumption about traffic or data size as an assumption.






