IndexedDbCacheSettings class final
Configures a cache stored in IndexedDB in the format of the official Firebase JS SDK, on the web, without SQLite
(no sqlite3.wasm to download, no openDatabase function).
The cache is the IndexedDB database the JS SDK's persistentLocalCache() uses for the same app and database,
firestore/<app name>/<project id>[.<database id>]/main (the app name is [DEFAULT] for the default app), at the
JS SDK's schema version 18, with its stores, keys and rows. A web app that used the JS SDK with a persistent cache
keeps its pending writes, cached documents, targets, cache indexes and loaded bundles when it switches to this SDK
on the same browser profile, and the JS SDK can open a cache this SDK wrote. A database of another schema version
is refused and left as it is: open the app once with a current JS SDK to migrate an older one. A new schema version
of the JS SDK needs a new release of this package.
Garbage collection runs as with PersistentCacheSettings, on the JS SDK's sequence numbers and size accounting
(sizeBytes). Cache indexes (indexAutoCreation, PersistentCacheIndexManager) are stored with the JS SDK's
encoding, so that indexes either SDK built serve the other.
One tab at a time, unless multiTab is set: the tab takes the JS SDK's primary lease as a JS tab with persistentSingleTabManager does, and
the instance fails to start (every operation fails with FirestoreErrorCode.failedPrecondition) while another
client (a tab of this SDK or of the JS SDK) holds a valid lease (refreshed less than 5 s ago, by a tab that did not
close). A JS tab that starts while this one holds the lease fails the same way. When the tab was in the background
long enough for its lease to lapse and another client took the cache over meanwhile, the instance terminates at its
next transaction or lease refresh, without writing: its query listeners get a
FirestoreErrorCode.failedPrecondition error that says it lost the primary lease, and every later call throws it.
The two SDKs can use the cache one after the other, not at the same time.
The engine is in its own library, so that apps that do not use it do not carry its code: create the settings with
indexedDbCacheSettings() of package:cloud_firestore_dart/indexeddb_cache.dart (it throws an UnsupportedError
on other platforms than the web).
import 'package:cloud_firestore_dart/indexeddb_cache.dart';
final FirebaseFirestore firestore = FirebaseFirestore.instanceFor(
app: app,
settings: Settings(cacheSettings: indexedDbCacheSettings()),
);
NOT IN THE OFFICIAL SDKS: the JS SDK always stores its persistent cache this way (persistentLocalCache); this SDK
stores it in SQLite by default (PersistentCacheSettings).
- Inheritance
-
- Object
- LocalCacheSettings
- IndexedDbCacheSettings
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- indexAutoCreation → bool
-
See PersistentCacheSettings.indexAutoCreation.
final
- indexBackfill → IndexBackfillSettings
-
See PersistentCacheSettings.indexBackfill.
final
- mergeUnsentWrites → bool
-
See PersistentCacheSettings.mergeUnsentWrites. The merged writes are stored as the JS SDK stores its writes: a
JS SDK that opens the cache afterwards sends them as they are.
final
- multiTab → bool
-
Whether the tabs of the app share the cache (
persistentMultipleTabManagerof the JS SDK) instead of one tab using it alone (the default). With it, one tab (the primary) uses the network for all of them; the others get its results and their online state throughwindow.localStorage, and one of them takes over when the primary closes. The instance fails to start wherelocalStorageis not available (a worker, or storage blocked). A one-tab client and a multi-tab client refuse each other, as in the JS SDK.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sizeBytes → int
-
The cache size threshold, in bytes.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override