Firestore 作为离线持久化机制的可靠性如何? [英] How reliable is Firestore as an offline persistence mechanism?

查看:18
本文介绍了Firestore 作为离线持久化机制的可靠性如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 Firebase Firestore 作为从各种来源检索数据的主要后端.我还使用 Android 的 Room 作为我的移动后端.当手机接收到数据时,它会存储在 Room 数据库中,以防用户数天甚至数周不再上网.

I am currently using Firebase Firestore as a primary backend that retrieves data from a variety of sources. I also use Android's Room for my mobile backend. When the phone receives data it is stored in the Room database in the event the user will not go online again for days even weeks.

查看设备文件后,我看到 firestore 将数据保存在 /data/data//databases 目录下的文件中.

After looking through the device files, I see firestore saves the data in files under the /data/data/<your-app>/databases directory.

文件看起来像这样

我已阅读 Firestore 上的离线持久性文档,但没有说明离线持久性的持久性.它提到数据已缓存但未缓存多长时间.我的问题是,Firestore 的离线持久性的持久性如何.是否建议使用它而不是使用成熟的本地数据库来存储可能不会在很长一段时间(几天、几周)内同步的数据?

I have read the offline persistence docs on the firestore and there is no indication on how durable the offline persistence is It mentions that the data is cached but not for how long. My question is, what is the durability of Firestore's offline persistence. Would one recommend using it instead of having a fully-fledged local DB to store data that may not be synced over long periods of time (days,weeks)?

一旦重新建立连接,它似乎已经可以很好地处理同步数据.我只是担心过了某个时间该文件可能会被系统删除而用户会丢失所有内容.

It seems to already handle syncing data well once a connection is re-established. Im just worried that after some point that file may be deleted by the system and the user loses everything.

推荐答案

在 Android 上(在撰写本文时)Firestore 使用 SQLite 作为持久性机制.因此,对于间歇性的离线活动,您应该不会出现性能或耐用性问题.

On Android (as of this writing) Firestore uses SQLite as a persistence mechanism. So for intermittent periods of offline activity you should have no problems with performance or durability.

但是,如果您要离线数天或数周(如您所说),则应注意以下事项:

However if you are going to be offline for days or weeks (as you said) there are some things you should be aware of:

性能

由于 Cloud Firestore 主要用于在线使用,因此尚未同步到服务器的待处理写入会保留在队列中.如果您在没有联机解决它们的情况下执行了许多挂起的写入,则该队列将会增长,并且会降低您的整体读/写性能.Cloud Firestore 的大部分性能保证来自后端的索引和复制,但当您仅离线操作时,大多数优化都不存在.

Because Cloud Firestore is meant to be used mostly online, pending writes that have not yet been synced to the server are held in a queue. If you do many pending writes without going online to resolve them, that queue will grow and it will slow down your overall read/write performance. Most of Cloud Firestore's performance guarantees come from indexing and replication on the backend, but most of those optimizations don't exist when you're operating offline-only.

冲突

Firestore 的基本冲突解决模型是最后写入获胜".因此,如果您有许多离线客户端写入同一个文档,那么只有最后一个上线的客户端才会真正获胜"并保持他们的更改.

Firestore's basic conflict resolution model is "last write wins". So if you have many offline clients writing to the same document, only the last one to come online will actually "win" and persist their change.

功能

Firestore 的大部分功能都可以离线使用,但有一个主要例外:事务.交易只能在您在线时执行.因此,如果您的应用使用事务,如果不进行一些特殊处理,它将无法正常离线工作.

Most of Firestore's features work offline with one major exception: transactions. Transactions can only execute when you are online. So if your app uses transactions it will not work properly offline without some special handling.

这篇关于Firestore 作为离线持久化机制的可靠性如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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