ColdStore class

A caching layer for Firestore documents that implements a three-tier caching strategy.

ColdStore provides three layers of data access:

  1. Memory cache for fastest access
  2. Persistent storage (JSON files) for offline capability
  3. Firestore as the source of truth

Example usage:

final coldStore = ColdStore();
final docRef = FirebaseFirestore.instance.doc('users/123');

// Start watching for changes
await coldStore.watch(docRef);

// Get document (checks all cache layers)
final doc = await coldStore.get(docRef);
final data = doc?.data();  // Get the document data
final userId = doc?.id;    // Get the document ID

// Clear cache when needed
await coldStore.clear(docRef);

// Clean up when done
await coldStore.dispose();

Constructors

ColdStore.new({FirebaseFirestore? firestore, bool autoWatch = true, bool cacheSizeUnlimited = false, int? maxCacheSize})
Creates a new ColdStore instance.

Properties

autoWatch bool
Whether to automatically watch documents when they're first accessed
final
currentCacheSize int
Gets the current cache size in bytes.
no setter
hashCode int
The hash code for this object.
no setterinherited
maxCacheSize int?
Gets the maximum cache size in bytes, or null if unlimited.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear(DocumentReference<Object?>? docRef) Future<void>
Clears cached data for a specific document or all documents.
dispose() Future<void>
Disposes of the ColdStore instance.
get(DocumentReference<Object?> docRef) Future<ColdStoreDocument?>
Gets document data from cache or Firestore.
getCacheStats() Map<String, dynamic>
Returns statistics about the current cache state.
getCollection(Query<Object?> query) Future<ColdStoreQuerySnapshot>
Gets documents from a collection or query.
isCacheNearlyFull([int threshold = 90]) bool
Returns true if the cache is approaching its size limit.
listActiveWatchers() Map<String, List<String>>
Lists all active watchers (listeners).
listCachedCollections() Future<Map<String, Map<String, dynamic>>>
Lists all cached collections.
listCachedDocuments() Future<Map<String, Map<String, dynamic>>>
Lists all cached documents.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
unwatch(DocumentReference<Object?> docRef) Future<void>
Stops watching a document for changes.
unwatchCollection(Query<Object?> query) Future<void>
Stops watching a collection for changes.
watch(DocumentReference<Object?> docRef) Future<void>
Starts watching a document for changes.
watchCollection(Query<Object?> query) Future<void>
Watches a collection or query for changes.

Operators

operator ==(Object other) bool
The equality operator.
inherited