存储库模式随着时间的推移在服务器上更改数据

时间:2021-02-08 02:20:03

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

我正在关注由着名的Robert C. Martin提出的清洁建筑。清洁建筑的鸟瞰图如下所示:

存储库模式随着时间的推移在服务器上更改数据 However right now my concern about Repository pattern modification. Basics steps of Repository pattern are:

但是现在我关注Repository模式修改。存储库模式的基础步骤是:

  1. Search in-memory cache AND provide data to app layer
  2. 搜索内存缓存并向应用层提供数据

  3. If not found, search local data source AND sync to in-memory cache AND provide data to app layer
  4. 如果未找到,请搜索本地数据源并同步到内存缓存并将数据提供给应用层

  5. If not found, search remote data source AND sync to local data source AND provide data to app layer
  6. 如果未找到,请搜索远程数据源并同步到本地数据源并向应用层提供数据

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 个解决方案

#1


0  

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

在RxJava的帮助下,您的想法符合我们的使用:Dan Lew很好地解释了

#1


0  

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

在RxJava的帮助下,您的想法符合我们的使用:Dan Lew很好地解释了