7 Cache Patterns at a Glance: Which One Should You Use?

7 Cache Patterns at a Glance: Which One Should You Use?

Series — 7 Cache Patterns (8 of 8 — hub). Publish this after the seven deep dives. Use it as the map: a short explanation of each pattern, when to pick it, and links to the full tutorials.

Introduction

Caching is not one technique. The same Redis (or Memcached / Caffeine) store can behave very differently depending on who loads data on a miss, what happens on a write, and how you handle hot keys when they expire.

This hub explains all 7 patterns in brief—enough to choose—then points you to the deep dive for diagrams, Laravel code, and failure modes. Primary stack in the series: Laravel + Redis (Spring @Cacheable / Caffeine where the idea maps 1:1).

The 7 patterns (quick map)

Map of seven cache patterns grouped into read path, write path, and miss storms

  1. Read path: cache-aside, read-through (+ refresh-ahead for freshness)
  2. Write path: write-through, write-behind, write-around
  3. Miss storms: request coalescing

1. Cache-aside

In one line: the app checks the cache; on a miss it reads the database, stores the result, and returns it.

This is the most common pattern. Your code owns keys, TTLs, and invalidation. Laravel Cache::remember() and Spring @Cacheable are everyday cache-aside.

Real-world fit: product detail pages, blog posts, category trees—read often, change sometimes.

  • Use when: read-heavy data and you want full control in application code
  • Avoid when: you need the cache library itself to own loading, or writes must keep the cache perfectly warm without a separate invalidation step
  • Watch out: forgetting Cache::forget after updates; hot-key stampedes at TTL expiry

Full guide: Cache-aside pattern explained.

2. Read-through

In one line: the app only calls get(key); on a miss the cache / loader reads the database and fills itself.

Miss-handling lives in one place. Call sites stay clean. Caffeine LoadingCache is the classic API; in Laravel you usually wrap remember inside a small service so every module talks to that service only.

Real-world fit: tenant settings, feature flags, shared reference data used by many classes.

  • Use when: the same load path is reused everywhere and you want one loader
  • Avoid when: each feature needs very different query/shaping logic at the call site
  • Watch out: slow loaders block every miss; in-process caches warm per server

Full guide: Read-through cache pattern explained.

3. Write-through

In one line: every write updates the database and the cache in the same request before success returns.

The next read can hit a warm, correct cache immediately—no waiting for TTL, no “I forgot to invalidate.” Prefer commit to DB first, then update the cache, so you never cache a value that never persisted.

Real-world fit: user profile after save, cart update then cart view, admin flag flip then next page check.

  • Use when: data is read right after it is written and staleness is painful
  • Avoid when: write volume is huge, or one write must touch many unrelated cache keys
  • Watch out: higher write latency; plan for “DB ok, cache put failed”

Full guide: Write-through cache pattern explained.

4. Write-behind

In one line: write the cache first (fast); flush to the database later in batches.

Also called write-back. Clients feel low latency under heavy write load. The trade-off is hard: if Redis or the process dies before flush, you can lose the last writes.

Real-world fit: article view counters, like tallies, game scores—high write rate, imperfect durability OK.

  • Use when: write flood would melt MySQL and losing recent increments is acceptable
  • Avoid when: money, inventory reservations, permissions, audit-critical data
  • Watch out: flush lag, double-flush bugs, silent dirty-queue growth—monitor it

Full guide: Write-behind cache pattern explained.

5. Write-around

In one line: writes go only to the database; the cache fills on the next read (if any).

This avoids cache pollution: filling Redis with keys nobody will read. On updates, still evict an old key if it might exist, so you never serve stale data—just do not put the new value in on write.

Real-world fit: CSV imports, audit logs, webhook storage, bulk inserts that are rarely opened one-by-one.

  • Use when: write-often / read-rarely workloads
  • Avoid when: the UI always reloads the entity right after save
  • Watch out: first read after write is a miss (slower once)—that is intentional

Full guide: Write-around cache pattern explained.

6. Refresh-ahead

In one line: hot keys reload in the background before hard expiry; readers keep getting the old value meanwhile.

Caffeine refreshAfterWrite is the textbook tool. With Laravel + Redis you approximate it: soft TTL triggers a locked background job; hard TTL remains the safety ceiling.

Real-world fit: homepage “trending” blocks, leaderboards, expensive menus—few keys, slow to load.

  • Use when: a small number of hot, expensive keys and slight staleness during refresh is fine
  • Avoid when: refreshing thousands of keys on a timer (refresh storms)
  • Watch out: no lock → many jobs reload the same query; combine with coalescing for true hard misses

Full guide: Refresh-ahead cache pattern explained.

7. Request coalescing

In one line: when many requests miss the same key at once, only one hits the database; the rest wait and share the result.

Also called singleflight / dogpile protection. Without it, hot-key TTL expiry becomes a self-inflicted stampede. In Laravel, a per-key Redis lock + double-checked get/put is the usual pattern.

Real-world fit: flash-sale product JSON, campaign landing payloads, any hot key with synchronized expiry.

  • Use when: expensive miss loads + traffic spikes on few keys
  • Avoid when: misses are cheap and rare (extra complexity for little gain)
  • Watch out: lock per key (not global); lock TTL must outlive the DB query; always re-check cache after winning the lock

Full guide: Request coalescing explained.

Comparison table

Pattern One-line idea Use when Watch out for
Cache-aside App checks cache; miss → DB → fill Read-heavy data; you want key/TTL control You must invalidate; stampedes on hot expiry
Read-through Cache loads on miss; app only talks to cache One loader shared by many call sites Heavy loaders; multi-node warm-up
Write-through Every write updates cache + DB together Read right after write; need fresh cache Higher write latency; multi-key fan-out
Write-behind Write cache first; flush DB in batches Heavy writes; loss of last writes OK Crashes; flush lag; not for money/stock
Write-around Write DB only; cache fills on next read Write-often, read-rarely; avoid pollution First read after write is a miss
Refresh-ahead Reload hot keys before expiry; serve old meanwhile Few slow hot keys Refresh storms if applied to everything
Request coalescing Many misses → one DB load; rest wait Stop stampedes on hot key expiry Lock tuning; still combine with refresh-ahead

Decision guide

  1. Mostly reads, editable data? Start with cache-aside + invalidate on update.
  2. Same load logic everywhere (settings, flags)? Prefer read-through.
  3. UI always reads what it just wrote? Use write-through.
  4. Write flood (counters) and losing recent increments is OK? Consider write-behind.
  5. Bulk writes nobody reads? Use write-around (+ evict if a key might exist).
  6. One expensive homepage/leaderboard key? Add refresh-ahead.
  7. Hot key TTL storms? Add request coalescing.

Patterns combine

Real systems mix patterns per data path—not one pattern for the whole app:

  • Product pages: cache-aside + invalidate on admin save + coalescing on miss
  • Homepage block: cache-aside + refresh-ahead + coalescing
  • View counters: write-behind to Redis, periodic DB flush
  • CSV import: write-around; single-order API read: cache-aside

Series reading order

  1. Cache-aside
  2. Read-through
  3. Write-through
  4. Write-behind
  5. Write-around
  6. Refresh-ahead
  7. Request coalescing
  8. This overview (hub)

Summary

Start with cache-aside or read-through for reads. Pick write-through, write-behind, or write-around based on how soon (and how often) data is read after a write. Protect hot keys with refresh-ahead and request coalescing. Use this page to choose; open each deep dive when you implement.

Topics
Development Laravel Database