python - 为 firebase-admin sdk 缓存 firestore 数据的最佳方法是什么?
问题描述
正如我可以找到的https://github.com/firebase/firebase-admin-python不允许enable offline data
模式。即使它有,我认为它也不足以满足我的用例。由于我知道我的数据库每天更新一次但读取多次,因此我希望始终从缓存中读取,除非缓存的数据超过 24 小时。
这就是我现在正在做的
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
cred = credentials.Certificate("firebase_admin_json_name.json")
firebase_admin.initialize_app(cred)
fdb = firestore.client()
source_doc_snapshots = (
fdb.collection("users")
.document(user)
.collection("sources")
.stream()
)
我正在寻找这样的东西(请为我的伪代码建议合适的代码)
if source_doc_snapshots in my cache > 24 hours old:
source_doc_snapshots = (
fdb.collection("users")
.document(user)
.collection("sources")
.stream()
)
save source_doc_snapshots to my cache
else:
read source_doc_snapshots from my cache
解决方案
推荐阅读
- ios - 在 Swift 中动态改变 SCNView 的背景
- apache-nifi - 使用 Nifi 计算目录中的文件数
- java - 如何修复 Cloud Bigtable Hello World 示例?
- reactjs - TODO 项目没有正常工作
- ios - 对 Delphi 的 Objective-c 完成处理程序
- python - Kivy倒计时应用程序
- javascript - 如何在 jQuery 中使用 HTML 模板标签?
- jquery - 如何使插入的项目可排序
- python - 为嵌套列表的每个元素添加前缀和后缀
- c# - Asp.net MVC 表单身份验证应用程序转换为 Azure Active Directory