Sometimes known as lazy-loading or cache-aside. This method is quite popular as it’s quite easy to implement without making loads of changes.
The flow of it is as follows:
- Client makes a request to read data
- Server checks if data exists in a cache
- When data exists in a cache, data is being returned
- If data do not exist in a cache, data is being fetched from a database
- data is being updated in a cache
- Data is being returned to a user
Transclude of Write-around-cache.excalidraw
Advantages
- Your cache stays slim because it only contains data that it needs
- Easy to implement and you get immediate gains
Disadvantages
- Cache is filled only after a cache miss, which means that you need to do 3 trips (Client → Server → cache → Server → Database → Server → Cache → Server → Client)