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

查看:89
本文介绍了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/<your-app>/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天全站免登陆