我遵循着名的 Robert C. Martin 提出的 Clean Architecture。 Clean Architecture 的鸟瞰图如下所示:
但是现在我担心存储库模式修改。 Repository 模式的基本步骤是:
- 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
严格按照上述步骤,如果本地数据源中存在数据,则永远不会从远程数据源同步,而远程数据可能会更改。我该如何修改才能处理这种情况?我想到了一个想法,写在下面,但我确实在寻找更好的解决方案。
我的想法是跟踪本地数据库中每条记录的上次同步时间。如果上次同步时间早于阈值时间,则自动同步。
最佳答案
在 RxJava 的帮助下,您的想法符合我们正在使用的内容: Dan Lew nicely explained at
关于android - 随着时间的推移在服务器上更改数据的存储库模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42612052/