Firebase脱机功能作为缓存 [英] Firebase offline capabilities as cache

查看:179
本文介绍了Firebase脱机功能作为缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否使用firebase离线功能作为一个免费缓存是一个合理的策略。
假设我在活动A中,我从firebase中获取一些数据,然后我转到活动B,需要相同的数据。如果应用程序配置了setPersistenceEnabled(true),如果有必要,还可以使用keepSynced(true),我可以重新查询活动B中的相同数据,而不是传递给它?
我理解这两种方法在从内存读取和从磁盘读取(firebase脱机缓存)方面存在差异。但是,我真的通过脱机使用firebase来摆脱所有的网络开销吗?


相关链接:


https://groups.google.com/forum/#!msg/firebase-talk/ptTtEyBDKls/XbNKD_K8CQAJ

解决方案 keepSynced())将其连接起来,所以会导致网络流量。



但不要将Firebase用作仅脱机数据库。它实际上被设计成一个在线数据库,可以在短时间内断开连接。脱机时将保持写入操作的队列。随着此队列的增长,本地操作和应用程序启动将会减慢。没什么大不了,但随着时间的推移,这些可能会加起来。


I am wondering whether it is a sound strategy to use the firebase offline capabilities as a "free" cache.

Let's assume that I am in activity A, I fetch some data from firebase, and then I move to activity B, which needs the same data. If the app is configured with setPersistenceEnabled(true) and, if necessary, also with keepSynced(true), can I just re-query the same data in activity B, rather that passing it around?

I understand that there is a difference between the two approaches regarding reading-from-memory and reading-from-disk (firebase offline cache). But do I really get rid of all the network overhead by using firebase offline?

Relevant links:
Firebase Offline Capabilities and addListenerForSingleValueEvent https://groups.google.com/forum/#!msg/firebase-talk/ptTtEyBDKls/XbNKD_K8CQAJ

解决方案

Yes, you can easily re-query your Firebase Database in each activity instead of passing data around. If you enable disk persistence, this will be a local read operation. But since you attach a listener (or keep it attached through keepSynced()), it will cause network traffic.

But don't use Firebase as an offline-only database. It is really designed as an online database that cam work for short to intermediate periods of being disconnected. While offline it will keep queue of write operations. As this queue grows, local operations and app startup will slow down. Nothing major, but over time these may add up.

这篇关于Firebase脱机功能作为缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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