Skip to content
pubscout

firestore_cache

2.21.7, released 3 weeks ago by an unverified publisher

Fetch Firestore documents with read from cache first then server based on a timestamp field.

WASM-readyUnverified publisher
$ flutter pub add firestore_cache
Source repository

What it does

A Flutter plugin designed to fetch documents and queries from Cloud Firestore by reading from the cache first and falling back or updating based on a designated timestamp field on a Firestore document.

AI-written summary of version 2.21.7, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to optimize Firestore read costs by serving cached data first.
  • You can manage timestamp fields in Firestore to signal when data updates should occur.

Skip it when

  • You require real-time automatic cache-to-server data comparison without managing manual timestamp fields.
  • You are using standard Firestore offline persistence which handles caching natively.

Strengths

  • Helps reduce Firestore read operations by utilizing local cache first.
  • Integrates seamlessly with cloud_firestore and shared_preferences.

Weaknesses

  • Relies entirely on a manually updated timestamp field to determine when to fetch from the server.
  • Requires extra setup steps involving creating tracking documents and fields on Firestore.

Setup

Kind
Flutter widgets
Effort
Medium
Code generation
No
Direct dependencies
2

Requires creating a specific document and a timestamp field in Firestore for each collection or document you want to fetch.

final cacheDocRef = Firestore.instance.doc('status/status');
final cacheField = 'updatedAt';
final query = Firestore.instance.collection('posts');
final snapshot = await FirestoreCache.getDocuments(
    query: query,
    cacheDocRef: cacheDocRef,
    firestoreCacheField: cacheField,
);

Alternatives

Packages that do the same job and could replace firestore_cache.

Works with

Packages commonly used together with firestore_cache: ones it builds on, ones built on it, and its own family.