cache_store library

A persistent cache in a key-value store that the app brings: implement CacheStore (an ordered store of byte keys and byte values: get, a range scan and an atomic write) and pass it to keyValueCacheSettings. The SDK lays the whole cache out in the store; see KeyValueCacheSettings for what the cache does and does not do yet.

A library of its own, so that only the apps that import it carry the code of the cache:

import 'package:cloud_firestore_dart/cache_store.dart';
import 'package:cloud_firestore_dart/cloud_firestore_dart.dart';

final FirebaseFirestore firestore = FirebaseFirestore.instanceFor(
  app: app,
  settings: Settings(cacheSettings: keyValueCacheSettings(store: myStore)),
);

One instance and one client use a store at a time: the SDK does not coordinate processes, isolates or tabs over a store. The writes of each transaction of the SDK are held in memory until it commits.

package:cloud_firestore_dart/cache_store_testing.dart has the checks of the contract a store must keep, to run in the tests of a store.

Classes

CacheStore
An ordered key-value store that holds the persistent cache of a Firestore instance, for an app that brings its own storage (see keyValueCacheSettings of package:cloud_firestore_dart/cache_store.dart).
CacheStoreEntry
A key and its value, as CacheStore.scan returns them and CacheStore.write takes them.
IndexBackfillSettings
The rate at which the persistent cache indexes are filled in the background, see PersistentCacheSettings.indexBackfill.
KeyValueCacheSettings
Configures a persistent cache in a key-value store that the app brings (CacheStore): an ordered store of byte keys and byte values, such as a file, an embedded database or a platform store.

Functions

compareCacheStoreKeys(List<int> a, List<int> b) → int
Compares two keys in the order of a CacheStore: by their unsigned bytes, the first differing byte deciding, and a key that is a prefix of another before it. For stores that keep their keys in a Dart collection (a SplayTreeMap with this as its comparator, for example).
keyValueCacheSettings({required CacheStore store, int sizeBytes = Settings.defaultCacheSizeBytes, bool indexAutoCreation = false, IndexBackfillSettings? indexBackfill, bool mergeUnsentWrites = false}) → KeyValueCacheSettings
Settings for a persistent cache in store, a key-value store the app brings (see KeyValueCacheSettings and CacheStore).