Repository pattern with changing data on server over time

2.1k Views Asked by At

I am following Clean Architecture proposed by famous Robert C. Martin. The birds eye view of Clean Architecture looks like as follows:

enter image description here However right now my concern about Repository pattern modification. Basics steps of Repository pattern are:

  1. Search in-memory cache AND provide data to app layer
  2. If not found, search local data source AND sync to in-memory cache AND provide data to app layer
  3. 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.

1

There are 1 best solutions below

0
miroslavign On

Your idea is in compliance with what we are using with a help of RxJava: Dan Lew nicely explained at