如何以离线模式保存部分Firebase实时数据库 [英] How to save a part of firebase realtime database in offline mode

查看:96
本文介绍了如何以离线模式保存部分Firebase实时数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将特定路径存储在本地电话存储中的Firebase数据库(JSON)中,而不是将所有数据存储在Realtime-Firebase数据库中.假设我在Firebase数据库中为每个用户提供了一条新闻提要路径,并且我只想保存为该用户指定的新闻提要,而不是将全部无用的数据加载到用户移动设备的本地存储中.

I wanted to store the specific path in Firebase database (JSON) in local phone storage, not all data at the realtime-Firebase database. Say I have a news-feed path for each user in my Firebase-database and I want to save only the news-feed which is specified for the user instead of loading whole useless data on the local storage of user's mobile.

我从官方

I read this paragraph from the official Firabase site which mentioned that

Firebase实时数据库为活动的侦听器同步并存储数据的本地副本.此外,您可以使特定位置保持同步.

The Firebase Real-time Database synchronizes and stores a local copy of the data for active listeners. In addition, you can keep specific locations in sync.

DatabaseReference scoresRef = FirebaseDatabase.getInstance().getReference("scores");
    scoresRef.keepSynced(true);

如果这是我的问题的解决方案,那么我可以直接使用此行而无需编写该行

If this is the solution to my question, then I can use this line directly without writing that line

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

推荐答案

这两位代码并不是真正相关的.他们做的不一样.

Those two bits of code are not really related. They don't do the same thing.

keepSynced(true)有效地使监听器从被调用的那一刻起就一直在给定引用上处于活动状态,只要应用程序正在运行,就可以始终在本地版本中使用数据与服务器上的远程版本同步.

keepSynced(true) effectively keeps a listener active on the given reference, from the moment it's called, for as long as the app is running, so that the local version of the data is always in sync with the remote version on the server.

setPersistenceEnabled(true)只会激活SDK读取的数据的本地缓存.启用持久性后,应用程序仍可以查询以前读取的数据.该功能对SDK读取的所有数据均有效.启用持久性后,您将无法控制要缓存的数据-所有读取的数据最多可以缓存10MB.达到最大值后,将从缓存中清除最旧的数据.

setPersistenceEnabled(true) just activates local caching of the data read by the SDK. When persistence is enabled, the app can still query data previously read. It takes effect for all data read by the SDK. While persistence is enabled, you can't control which data is cached - all read data is cached up to 10MB max. When the max is reached the oldest data will be evicted from the cache.

这篇关于如何以离线模式保存部分Firebase实时数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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