将Firebase Persistence Enabled设置为true后,是否不检索新数据? [英] Not retrieving new data after setting Firebase Persistence Enabled to true?

查看:110
本文介绍了将Firebase Persistence Enabled设置为true后,是否不检索新数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

制作FirebaseDatabase.getInstance().setPersistenceEnabled(true);查询数据后

Query  query = FirebaseDatabase.getInstance()
                      .getReference()
                      .child("notifications")
                      .child("entities")
                      .child(FirebaseAuth.getInstance().getCurrentUser().getUid().toString())
                      .orderByChild("seen")
                      .equalTo(0); 

来自数据树

它提供缓存中的旧数据,而不是Firebase数据库中的新更改数据.但是当我将setPersistenceEnabled(true)更改为setPersistenceEnabled(false)时,一切都很好同时,我也希望将Firebase数据作为保留在缓存中并进行更改对Firebase数据库进行更改时.请帮助保持Firebase数据持久性以及实时更改.

it gives old data that is in cache instead of new changed data in Firebase databse.But When I change setPersistenceEnabled(true) to setPersistenceEnabled(false) then everything is fine While I also want firebase data to be persisted in cache and also change When change is made to Firebase database.Please help to maintain Firebase data persistence along with realtime change.

推荐答案

如果使用的是:

setPersistenceEnabled(true);

这意味着即使您处于脱机状态,您也可以查询数据库.发生这种情况是因为Firebase创建了数据库的本地副本,该副本在应用程序/设备重新启动后将继续存在.当您离线时,您在离线状态下所做的所有更改都会在Firebase服务器上进行更新.更清楚地说,每个使用Firebase数据库并使用setPersistenceEnabled(true)的客户端都维护其自己的数据库内部(本地)版本.数据更新后,首先将其写入数据库的此本地版本.

It means that you'll be able to query your the database even if you are offline. This is happening because Firebase creates a local copy of your database that will persist after your app/device restarts. Every change that is made while you are offline, will be updated on Firebase servers once you are back online. To be more clear, every client that is using a Firebase database and uses setPersistenceEnabled(true) maintains it's own internal (local) version of the database. When data is updated, it is first written to this local version of the database.

因此,通过启用持久性,即使用户或操作系统重新启动应用程序,Firebase Realtime数据库客户端在联机时将同步的任何数据,可持久保存到磁盘且可脱机使用的数据.这意味着您的应用程序将通过使用存储在缓存中的本地数据像在线一样正常工作.

So, 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 that your app will work as it would be online by using the local data stored in the cache.

但是,当您未连接到服务器时,无法停止从缓存中检索数据,因为不幸的是,当您连接到服务器时,无法强制从缓存中检索数据.此行为无法更改.

But, there is no way to stop the retrieval of the data from the cache while you are not connected to the server, as you cannot force the retrieval of the data from the cache while you're connected to the server and unfortunately this behaviour cannot be changed.

这篇关于将Firebase Persistence Enabled设置为true后,是否不检索新数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆