Caching Strategies Cheat Sheet

  • 2 Strategies
    • Lazy loading
      • When something is requested from cache and cache misses, cache request it from origin
      • This is the strategy used by CDNs
    • Write-through
      • When origin is updated, update cache at the same time
  • Compare 🎓
    • Lazy loading
      • Good
        • Low storage needs = only cache requested data
        • Fault-tolerant = replaced nodes only increases latency but can work normally
      • Bad
        • Cache miss = latency
        • Stale data = no way to update cache when origin data is updated
          • Use TTL or use write-through
    • Write-through
      • Good
        • Up-to-date = no stale data
        • No cache miss penalty
      • Bad
        • Write penalty = every writes incurs writing to both cache and database
        • Faults result in missing data = when node is replaced there will be a time window of data not written to cache thus missing
          • Add lazy-loading
        • Wasted storage = most data are not accessed but will account into cache storage
          • Use TTL
  • Strategies not exclusive, and be combined and should