firestore_cache
一个用于从缓存中优先读取,然后从服务器获取 Firestore 文档的 Flutter 插件
一个用于从缓存优先读取然后从服务器获取 Firestore 文档的 Flutter 插件。
以下为英文项目原文快照,最新内容请访问 GitHub。
A Flutter plugin for fetching Firestore documents with read from cache first then server.
This plugin is mainly designed for applications using the DocumentReference.get() and Query.get() methods in the cloud_firestore plugin, and is implemented with read from cache first then server.
Add this to your package's pubspec.yaml file:
dependencies:
firestore_cache: ^2.21.2
Before using the plugin, you will need to create a document on Firestore and create a timestamp field in that document. See the screenshot below for an example:
⚠️ PLEASE NOTE This plugin does not compare the documents in the cache and the ones in the server to determine if it should fetch data from the server. Instead, it relies on the timestamp field in the document to make that decision. And so your application should implement the logic to update this field if you want to read new data from the server instead of reading it from the cache.
You should also create different timestamp fields for different collections or documents that you are fetching.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firestore_cache/firestore_cache.dart';
// This should be the path of the document containing the timestamp field
// that you created
final cacheDocRef = Firestore.instance.doc('status/status');
// This should be the timestamp field in that document
final cacheField = 'updatedAt';
final query = Firestore.instance.collection('posts');
final snapshot = await FirestoreCache.getDocuments(
query: query,
cacheDocRef: cacheDocRef,
firestoreCacheField: cacheField,
);
依赖清单 7 项
^6.9.0{"sdk":"flutter"}^2.5.52.16.16.0.0{"sdk":"flutter"}1.0.5先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗