Your cache is a volatile data storage, you must write your software so that it EXPECTs that the cache is unavailable. eg.
public DtoThing GetSomeData(string parameters) { if (<check cache for data> == <not there>) return <get data from persistent store> else return <get data from cache> }
If you use the database as a backup storage for the cache, you basically just get rid of all the benefits of using the cache. When you say that the cache should be reliable, do you say that the updates should be consistent or that the data should always be in the cache? If the first, itβs easy to make sure that this happens as long as you write your software in such a way that there is only one way to update the data, and then this way can lead to invalidation of the cache if it was successfully written to the permanent data store.
source share