Application is responsible for reading and writing to the DB (using write-through or write-back policy)
The cache doesn't interact with the storage directly
Cache aside:
- Data model can be different from DB
Read-through:
- Same data model as DB
- Can use the refresh-ahead pattern
- LRU (Least Recently Used)
- LFU (Least Frequently Used)
- FIFO
- Client caching
- CDN
- In memory
- Distributed cache
- Database caching (query or object)
Cache to automatically refresh any recently accessed entry prior to its expiration
Used with read-through cache
- Pro: can result in reduced latency
- Con: not accurately predicting which items are likely to be needed in the future
Main difference: consistency
Write through:
- Write to the cache and the DB in a single DB transaction (may still lead to cache inconsistency if the DB commit failed)
- Return
Write back:
- Write to the cache
- Return
- Asynchronously store in DB
- Improve read latency
- Can improve availability (e.g., DB unavailable, responses are served from the cache)
- Save computation time (e.g., SQL computation)
- Independently scalable from the rest of the system
Cache hit ratio: hits / total accesses
Read-through cache sits in-line with the DB
Single entry point
- Speed up reads
- Response complex to compute