1. Cache pattern
Cache-aside has the app check the cache first and load from the database on a miss; read-through and write-through put that logic in the cache layer.
pattern: cache-asideTyporithm · medium
Step 1 of 8 · intro card
Scaling
Cache-aside, read-through, and write-through are the common patterns. Eviction policies (LRU/LFU) decide what to drop, TTLs bound staleness, and caches stack from browser to CDN to app to DB. Invalidation and stampede protection are the hard parts; Redis and Memcached are typical stores.
Caching keeps hot data in fast storage to cut latency and offload the backend. In cache-aside, the app checks the cache and falls back to the database on a miss, then stores the result. Read-through and write-through push that read/write logic into the cache layer itself.
A cache has finite space, so an eviction policy decides what to drop when it fills up: LRU evicts the least-recently-used entry, LFU the least-frequently-used. A TTL expires entries after a fixed window, bounding how stale a value can become.
Caches form layers — browser, CDN, application, and database — each shielding the one below it. The genuinely hard parts are invalidation (keeping cached copies consistent with the source) and stampede protection (stopping many clients from rebuilding the same expired entry at once). Redis and Memcached are the usual stores.
Patterns: cache-aside, read-through, write-through.
Eviction: LRU drops least-recently-used, LFU least-frequently-used.
TTL bounds staleness; invalidation is the hard problem.
caching:
pattern: cache-aside
eviction: lru-or-lfu
ttl: bound-staleness
layers: cdn-app-db
invalidation: hardest-problemConnect each part of the code to the concept before you type.
Cache-aside has the app check the cache first and load from the database on a miss; read-through and write-through put that logic in the cache layer.
pattern: cache-asideWhen the cache is full, LRU drops the least-recently-used entry and LFU drops the least-frequently-used one.
eviction: lru-or-lfuA TTL expires entries after a set time, bounding how stale a cached value can get.
ttl: bound-stalenessCaches stack from the browser through a CDN to the application and database, each absorbing reads from the layer below.
layers: cdn-app-dbKeeping cached data consistent with the source — invalidation and stampede protection — is the famously hard part of caching.
invalidation: hardest-problemRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.