ਬੁਨਿਆਦੀ cache-aside ਤੋਂ ਬਾਹਰ, ਕਈ caching strategies ਹਨ — cache-aside, write-through, write-behind, read-through — ਹਰ ਇਕ ਦੇ ਵੱਖ-ਵੱਖ consistency ਅਤੇ performance trade-offs ਹਨ। ਇਹਨਾਂ ਨੂੰ ਸਮਝਣਾ (ਅਤੇ eviction policies) ਪ੍ਰਭਾਵਸ਼ਾਲੀ caching ਡਿਜ਼ਾਇਨ ਕਰਨ ਵਿੱਚ ਮਦਦ ਕਰਦਾ ਹੈ।
Cache-aside (lazy loading — ਸਭ ਤੋਂ ਆਮ)
App checks cache → miss → load from DB → populate cache → return.
✓ Only requested data is cached (efficient); resilient (works if cache is down)
✗ First request is a miss (slower); cache can be stale until TTL/invalidation
→ The default, most common strategy.
Write-through ਅਤੇ write-behind
WRITE-THROUGH → write to cache AND DB together (synchronously) on every write
✓ Cache always fresh/consistent ✗ Writes are slower (two writes); caches unread data
WRITE-BEHIND (write-back) → write to cache immediately, write to DB ASYNC later
✓ Fast writes ✗ Risk of data loss if cache fails before the DB write; more complex
