SteelReed

Search

Search posts, questions…

Caching & RedisQuestion 1 / 24

Junior

What is a cache, and which layers can you cache at?

Short answer

A cache is a temporary copy of data that is read often or costly to compute, placed closer to the user or faster than the source. Gains: lower latency, less DB load; costs: data can be stale and you must handle invalidation.

missmissmissmissBrowserCDNGateway, NginxApp: CaffeineRedisDB, buffer pool

3 points to say:

  1. Cache = a temporary copy, faster or closer than the source: Caffeine ~100 ns, Redis ~0.2–0.5 ms, an indexed query ~1–5 ms.
  2. Gains: latency, DB load, computation; costs: stale data, one more thing to run, the invalidation problem.
  3. Caches live at many layers: browser, CDN, proxy, in-app, Redis, DB; each layer caches a different kind of data.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.