Firebase 离线持久性 - 可以进行前期缓存吗?
Firebase offline persistence - Upfront caching possible?
我正在使用 Cloud Firestore 数据库开发 Firebase Web 应用程序。现在
我正在试验 offline persistence ,它目前按预期工作。到目前为止我遇到的唯一缺点是只有在我已经获取数据时才会缓存数据(这是有道理的)。
我想让我的应用程序中的某些页面/数据可以离线访问。这仅在用户在离线前导航到这些页面时才有效。
有什么技巧可以将数据添加到 Firebase 缓存中吗?诸如“使这个和那个集合/查询离线可用”之类的东西?这可能称为前期缓存。
提前感谢您的任何提示!
请参考接受的答案,这是一个更好的解决方案
----------------------------我的原始答案------------ ------------------
There is no official way to do this. But, there is a hack to achieve
upfront caching. Simply read the needed data in your collection on the
initial app open or when the app is idle.
Caution: This may increase your firestore read count!!
But surely this will work.
这在过去是不可能的(正如 Soorya 所回答的那样),但随着 Firestore content bundles. With these you can create a bundle (for example as part of your release process), include that in your app as an included binary, and then ingest the bundle into Firestore when the app is first loaded on the user's device. In addition to the linked documentation, I also recommend checking out the solutions page on serving bundles 的引入而成为可能。
我正在使用 Cloud Firestore 数据库开发 Firebase Web 应用程序。现在 我正在试验 offline persistence ,它目前按预期工作。到目前为止我遇到的唯一缺点是只有在我已经获取数据时才会缓存数据(这是有道理的)。
我想让我的应用程序中的某些页面/数据可以离线访问。这仅在用户在离线前导航到这些页面时才有效。
有什么技巧可以将数据添加到 Firebase 缓存中吗?诸如“使这个和那个集合/查询离线可用”之类的东西?这可能称为前期缓存。
提前感谢您的任何提示!
请参考接受的答案,这是一个更好的解决方案
----------------------------我的原始答案------------ ------------------
There is no official way to do this. But, there is a hack to achieve upfront caching. Simply read the needed data in your collection on the initial app open or when the app is idle.
Caution: This may increase your firestore read count!!
But surely this will work.
这在过去是不可能的(正如 Soorya 所回答的那样),但随着 Firestore content bundles. With these you can create a bundle (for example as part of your release process), include that in your app as an included binary, and then ingest the bundle into Firestore when the app is first loaded on the user's device. In addition to the linked documentation, I also recommend checking out the solutions page on serving bundles 的引入而成为可能。