Repository pattern with changing data on server over time

iam*_*der 5 android repository-pattern data-layer restful-architecture clean-architecture

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:

  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. 如果没有找到,搜索远程数据源并同步到本地数据源并向应用层提供数据

严格按照上述步骤操作,如果本地数据源中存在数据,它将永远不会从远程数据源同步,而数据可能会在远程更改。我该如何修改才能处理这种情况?一个想法出现在我的脑海中,写在下面,但我确实在寻找更好的解决方案。

我的想法是跟踪本地数据库中每条记录的上次同步时间。如果上次同步时间超过阈值时间,则自动同步。

mir*_*ign 0

您的想法与我们在 RxJava 的帮助下使用的内容一致: Dan Lew 在