5

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.

iamcrypticcoder
  • 2,609
  • 4
  • 27
  • 50
  • Maybe you should skip number 3 from your Repository responsibilities You could subscribe to remote data source notifications instead and update your local store whenever changes happen. – MaxSC Mar 06 '17 at 13:32
  • @MaxSC How to implement subscription for remote data source changes for a particular set of data ? My remote server built upon node js. – iamcrypticcoder Mar 06 '17 at 13:47
  • Have a look at [firebase cloud messaging](https://firebase.google.com/docs/cloud-messaging/) and it seems like there are a lot of npm packages that wrap it up [here](https://www.npmjs.com/package/fcm-node) and [here](https://www.npmjs.com/package/fcm) and [here](https://www.npmjs.com/package/fcm-push).... But I never used one of those :) – MaxSC Mar 06 '17 at 14:03

1 Answers1

0

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

miroslavign
  • 2,033
  • 2
  • 24
  • 26