Firebase keepSynced(true) [英] Firebase keepSynced(true)

查看:53
本文介绍了Firebase keepSynced(true)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Firebase数据库中的多个路径上使用同步时,需要权衡些什么?

What are the trade-offs when I use sync on several paths in my Firebase database?

databaseRef.keepSynced(true);

我从不清除这些路径的同步.

I never clear the sync from these paths.

此外,我可能将其称为databaseRef.keepSynced(true);.在同一条路径上几次.有问题吗?

In addition, I might call databaseRef.keepSynced(true); several times on the same path. Is t a problem?

我也在使用

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

那么,就电池寿命,内存问题而言,我该为同步支付多少钱呢?

So what do I "pay" for this sync in terms of battery life, memory issues?

推荐答案

使用 keepSynced()方法时,您告诉Firebase从 databaseRef下载并缓存所有数据..我希望 databaseRef 不是数据库的根引用,因为如果是,则您正在下载整个数据库,这不是一个好习惯.

When you use the keepSynced() method, you're telling Firebase to download and cache all the data from databaseRef. I hope databaseRef isn't the root Reference of your Database because if it is, you're downloading your entire database and this is not a good practice.

您应该使用 keepSynced()来缓存应用程序脱机真正需要的节点.

You should use keepSynced() to cache nodes that are really necessary for your app to work offline.

您可能会想知道它与 setPersistanceEnabled(true)有什么不同.好吧, setPersistanceEnabled(true)仅在有附加到该节点的侦听器时(至少读取一次数据)才缓存数据.

You will probably be wondering how is it different from setPersistanceEnabled(true). Well, setPersistanceEnabled(true) only caches data when there is a Listener attached to that node (when the data has been read at least once).

另一方面,即使没有连接侦听器, keepSynced(true)也会缓存该节点中的所有内容.

On the other hand, keepSynced(true) caches everything from that node, even if there is no listener attached.

这篇关于Firebase keepSynced(true)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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