Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Caching Strategies?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ansh44233-caching-strategies)
---
description: Add caching (HTTP, CDN, in-process, Redis) with correct keys, TTLs, invalidation and stampede protection
profile: standard
tags: caching, performance, backend
---
# Caching strategies
Use when adding a cache or debugging stale or inconsistent data.
## Decide first
1. Measure: what is slow, and how often is the same answer requested? Cache only what is expensive and reused.
2. Choose the layer: HTTP caching (`Cache-Control`, `ETag`) and CDN for public responses, in-process for small hot data, Redis/Memcached for data shared across instances.
3. Decide the staleness the product can accept. That number is your TTL.
## Correctness
- Key everything that changes the answer: user or tenant id, locale, permissions, query parameters, API version. A missing key component leaks one user's data to another.
- Never cache responses that include `Set-Cookie` or personal data in a shared cache; use `Cache-Control: private` or `no-store`.
- Invalidate on write (delete the key after the transaction commits) or use versioned keys; TTL is the safety net, not the plan.
- Cache-aside: read the cache, on miss load from the source and set the key. Handle cache outages by falling back to the source.
## Stampedes and memory
- Protect hot keys from thundering herds with request coalescing (single-flight), locks, or probabilistic early refresh.
- Bound in-process caches (LRU with a max size). Set `maxmemory` and an eviction policy on Redis.
- Add jitter to TTLs so keys do not expire together.
## Verify
Tests for hit, miss, invalidation after write, and per-user isolation. Watch hit ratio and latency after release.