Trung BìnhRedis iconRedis

Các caching strategies: Cache-Aside, Write-Through, Write-Behind — khi nào dùng cái nào?

Cache-Aside (Lazy Loading): application tự quản lý cache.

  • Read: check cache → miss → query DB → set cache → return.
  • Write: update DB, invalidate hoặc update cache.
  • Ưu điểm: chỉ cache data thực sự được request (no unnecessary warming); linh hoạt.
  • Nhược điểm: cache miss gây thêm latency, cold start problem, potential stampede.
  • Phổ biến nhất cho read-heavy workloads. Write-Through: mỗi write cập nhật cả DB lẫn cache đồng thời (application hoặc cache layer).
  • Ưu điểm: cache luôn fresh.
  • Nhược điểm: write latency cao hơn; cache nhiều data ít được đọc (waste memory).
  • Tốt cho write-then-read workloads. Write-Behind (Write-Back): write vào cache trước, batch flush xuống DB async sau.
  • Ưu điểm: write latency cực thấp, reduce DB write load.
  • Nhược điểm: risk data loss nếu cache fail trước khi flush; eventual consistency.
  • Dùng cho: high-frequency write (game score, view counter, shopping cart), khi DB write là bottleneck.

Xem toàn bộ Redis cùng filter theo level & chủ đề con.

Mở danh sách Redis