There are many types of cache strategies like cache aside, read through, write through, write back, refresh aside, write around and more. I will talk about four of them.
Cache Aside: The application first checks the cache. If the data is not found in cache it queries the database to read the data, returns it to the client and stores the data in cache.
Faster in read heavy applications
No direct connection between cache and database
Use TTL for remain consistent between cache and database
Read Through: The application first checks the cache. If the data is not found in cache it queries the database to read the data, populates the cache and returns it to the application.
Need a library or some separate cache provider
Cache and database data always remain consistent
Cache sits in-line with the database
Write Through: Data is first written to the cache and then to the database. The cache sits in-line with the database and writes always go through the cache to the main database.
Cache maintains consistency with the main database.
Write heavy workloads like multiplayer games
Write Back: Here, the application writes data to the cache which stores the data and acknowledges the application immediately. A modified cache block is written back to the database, just before it is replaced.
Asynchronous between cache and database
Reduce write operations in write heavy applications
Writing to the database with a delay
References:
Comments
Post a Comment