保持收集数据离线可用(0 - 100 个文档)并在连接可用时在应用程序启动时同步它的最佳方法是什么?
UPD:我正在寻找 setPersistenceEnabled,但是否可以保证我的收藏在第一次检索后会被缓存?
最佳答案
如果您调用 setPersistenceEnabled(true),这些文档将可以离线使用并在连接再次可用时同步(不一定在应用程序启动时)。检查文档: https://firebase.google.com/docs/database/android/offline-capabilities
By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache. Listener callbacks will continue to fire for local updates.
另请注意,当您使用此功能时,您的监听器将在应用程序启动时被调用两次!一个 - 用于离线(缓存)数据,第二个 - 在线(从 firebase 读取)。
关于flutter - 保持 firesotrore 集合离线可用并在前台同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54304004/