caching-strategylisted
Install: claude install-skill tmj-90/gaffer
# Add or fix a cache
A cache trades freshness for speed, and every cache goes stale in a specific way. Write
the story before the code: key, scope, lifetime, invalidation, the race that can leave a
stale value behind, and what happens when the cache is down. A cache without an
invalidation plan is a bug on a delay.
## Steps
1. **Prove the need.** A measurement showing the same expensive read repeated (the
`performance-profiling` skill). If the fix is "stop calling it twice", batch the
query, or add an index (the `sql-query-performance` skill), do that instead.
2. **Choose the innermost layer that solves it.** Request-scoped memo (no invalidation
problem); process memory (fast, per instance, diverges across instances); a shared
store such as Redis (consistent across instances, one more dependency); HTTP caching
(RFC 9111: `Cache-Control`, `ETag`/`If-None-Match` → `304`, CDN). Call `search_lore`
for the repo's cache helper, key prefixing and serializer; use it.
3. **Design the key.** Every input that changes the output is in the key: identifiers,
tenant, the caller's permission scope, locale, query parameters, and a schema or code
version. Missing tenant = data leak; missing version = old shapes after a deploy.
HTTP: `Vary` on every request header the response depends on.
4. **Set the TTL from the data.** Ask how stale this can be before someone is harmed;
that is the TTL. Add ±10–20 % jitter so keys written together do not expire together.
T