I am following Clean Architecture proposed by famous Robert C. Martin. The birds eye view of Clean Architecture looks like as follows:
However right now my concern about Repository pattern modification. Basics steps of Repository pattern are:
- Search in-memory cache AND provide data to app layer
- If not found, search local data source AND sync to in-memory cache AND provide data to app layer
- If not found, search remote data source AND sync to local data source AND provide data to app layer
Following above steps strictly, if a data exists in local data source it will never sync from remote data source while data might be changed in remote. How can I modify so that this case could be handled ? One idea comes in my mind written below, but I am looking to a better solution indeed.
My idea is to keep track of last sync time for each record in local database. If last sync time is more than a threshold time ago, then sync automatically.