Cache-aside, read-through, write-through, write-back
A cache sits in front of your database and answers the common reads from memory. This guide is about keeping the two in step: who puts data into the cache, and what happens when the data changes. There are four patterns, and interviewers expect you to pick one and say why.
The corner shop
A shopkeeper keeps a small price sheet on the counter for the things people ask about all day. The full price ledger is in the back room. If a price is on the sheet, the answer is instant. If it isn't, the shopkeeper walks to the back, reads the ledger, and copies the price onto the sheet for next time.
The sheet is the cache: small, fast, sometimes out of date. The ledger is the database: complete, slower, always right. The shopkeeper is your code on the app server, which checks the sheet and does the walking. The four patterns are four answers to one question: when a price changes, which do you fix, and when?