educative.io

How does read through cache always stays consistent with db?

" A subtle difference from the cache aside strategy is that the cache always stays consistent with the database in the read-through strategy.

The cache library, or the framework, takes the onus of maintaining consistency with the backend."
What cache library does to make cache consistent with db ?

  1. is it periodically poll db for changes? it does not guarantee data is consistent between period.
  2. Cache subscribes for changes in db ? it does not guarantee data is consistent until cache has successful updated data.

@Thien_Nguyen This largely depends on the underlying implementation of the library/framework. Yes, there may be data inconsistency possibility if the cache receives a request for data before it updates itself. In scenarios, where we need strict data consistency we can use a write-through cache. In this case, the data in the cache and the database will always be consistent.