避免在应用程序启动时一遍又一遍地从 Firestore 获取相同的数据

Avoid fetching the same data from Firestore over and over again whenever the app starts

对不起,如果这是一个愚蠢的问题。我开始在 SwiftUI iOS 应用程序中使用 Firestore 数据库。因为每次 read/write/delete 我都会被收费,所以我尽量避免在用户每次启动应用程序时读入包含大量文档的快照(例如 Messenger 应用程序中的消息)。

我想知道正常的处理方法是什么?我是否必须 write/save 本地消息到 sqlite 或领域以便下次从内部数据库中获取它们(在 Firestore 端我创建一个查询 read/load 只有比最后本地保存的消息)?或者 Firestore (Firebase) 是否有内置解决方案,例如缓存?

我想你已经回答了你的问题。您可以在本地保存文档(消息),这样您就不必每次都从 Firestore 中获取它们(并且只获取新的)。 Firebase 可以 cache data locally, but only 。使用 sqlite、realm 甚至 CoreData 保存数据是明智之举。