caching
SKILL.md
Caching Patterns
A well-placed cache is the cheapest way to buy speed. A misplaced cache is the most expensive way to buy bugs.
Cache Strategies
| Strategy | How It Works | When to Use |
|---|---|---|
| Cache-Aside (Lazy) | App checks cache → miss → reads DB → writes to cache | Default choice — general purpose |
| Read-Through | Cache fetches from DB on miss automatically | ORM-integrated caching, CDN origin fetch |
| Write-Through | Writes go to cache AND DB synchronously | Read-heavy with strong consistency |
| Write-Behind | Writes go to cache, async flush to DB | High write throughput, eventual consistency OK |
| Refresh-Ahead | Cache proactively refreshes before expiry | Predictable access patterns, low-latency critical |
Cache-Aside Flow:
App ──► Cache ──► HIT? ──► Return data
│