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

FirestoreCache()

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<String, dynamic>> docRef, {Source source = Source.cache, bool isRefreshEmptyCache = true}) Future<DocumentSnapshot<Map<String, dynamic>>>
Fetch a document with read from cache first then server.
getDocuments({required Query<Map<String, dynamic>> query, required DocumentReference<Map<String, dynamic>> cacheDocRef, required String firestoreCacheField, String? localCacheKey, bool isUpdateCacheDate = true}) Future<QuerySnapshot<Map<String, dynamic>>>
Fetch documents with read read from cache first then server.
isFetchDocuments(DocumentReference<Map<String, dynamic>> cacheDocRef, String firestoreCacheField, String localCacheKey) Future<bool>