I have one doubt , By removing responsibility from Application to call database for read through cache, are we not giving more responsibility to Cache which should only provide data to Application only and not make a call to database for read ?
It's because cache is primarily used to store most frequently accessed data and we want to optimise on cache hit as much as possible. The application might need the required data multiple times, and calling DB for such a use case is unnecessary and defeat the purpose of using a Cache. That's why it's necessary to also do writes to the cache(to minimise the cache misses), and the onus of Calling DB in such a case falls on Caches. I hope it make sense.
Hi Vivek, again Great Read :)
I have one doubt , By removing responsibility from Application to call database for read through cache, are we not giving more responsibility to Cache which should only provide data to Application only and not make a call to database for read ?
It's because cache is primarily used to store most frequently accessed data and we want to optimise on cache hit as much as possible. The application might need the required data multiple times, and calling DB for such a use case is unnecessary and defeat the purpose of using a Cache. That's why it's necessary to also do writes to the cache(to minimise the cache misses), and the onus of Calling DB in such a case falls on Caches. I hope it make sense.