Skip to content
PSPriya Singh1mo ago

How does caching work and what should I cache first?

I know 'caching makes things fast' but where does one actually start on a real app — browser, CDN, Redis? What's the order?
77
1 answers2.8K views

1 Answer

Accepted answer

RNRahul N.2.1K XP1mo ago
Caching = keep a copy of expensive-to-compute data somewhere cheap to read. The order that pays off: 1. HTTP/CDN caching (free wins) — static assets with long cache headers; whole pages if they're the same for everyone. 2. Database query results — that homepage query joining five tables and running on every visit? Cache it for 60 seconds in Redis. A 60s TTL on hot reads can cut database load by 90%+. 3. Computed objects — rendered fragments, aggregated counts, expensive API responses. Two rules that save you pain: every cache entry gets a TTL (no 'cache forever'), and know your invalidation story before you cache — stale-and-eventually-refreshed is fine for a feed, unacceptable for a bank balance.
69

Know the answer?

Join Nobink to answer, vote and build your reputation.