FirestoreCache class
FirestoreCache is a Flutter plugin for fetching Firestore documents with read from cache first then server.
Before using this plugin, you will need to do some initial setup on Firestore. Then you can use this sample code to fetch documents:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firestore_cache/firestore_cache.dart';
// This should be the path of the document containing the timestampe 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,
);
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getDocument(
DocumentReference< Map< docRef, {Source source = Source.cache, bool isRefreshEmptyCache = true}) → Future<String, dynamic> >DocumentSnapshot< Map< >String, dynamic> > - Fetch a document with read from cache first then server.
-
getDocuments(
{required Query< Map< query, required DocumentReference<String, dynamic> >Map< cacheDocRef, required String firestoreCacheField, String? localCacheKey, bool isUpdateCacheDate = true}) → Future<String, dynamic> >QuerySnapshot< Map< >String, dynamic> > - Fetch documents with read read from cache first then server.
-
isFetchDocuments(
DocumentReference< Map< cacheDocRef, String firestoreCacheField, String localCacheKey) → Future<String, dynamic> >bool>