gpt4 book ai didi

firebase - 基于firestore快照强制流读取缓存

转载 作者:行者123 更新时间:2023-12-03 04:38:18 25 4
gpt4 key购买 nike

我正在尝试在我的应用中从 SQLite 切换到 Cloud Firestore。当然,我正在尝试减少从 Cloud Firestore 读取的次数。
我从 Cloud Firestore 获得这样的流:

list = fireStore.collection('users')
.document('public')
.collection('info').orderBy("date")
.snapshots();
将读取集合“信息”中的所有文档。第一次读取时,我想强制将来读取来自缓存。直到,比方说,20天过去了。然后我想更新缓存。
据我了解,可以使用 DocumentReference.get() 和 Query.get() ( click here to find out how ),但据我所知,我的解决方案不可能。
我是否需要改变我的方法并实现上述方法之一,或者在我使用它时是否有针对流的解决方法?

最佳答案

snapshots FlutterFire 中的方法相当于 onSnapshot in the native SDKs .这些方法监听本地缓存和服务器上的更改,否则无法配置。get()原生 SDK 中的方法 FlutterFire可以配置为从特定来源获取文档。所以如果你想强制从本地缓存中读取,你必须使用 get(GetOptions(source: Source.cache)) .
另一种方法可能是 explicitly manage network access对于 Firestore 客户端。

关于firebase - 基于firestore快照强制流读取缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63712571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com