I'd like to use just a single method of persistence in my app, and am using Cloud Firestore for my premium/paying users.
Is it possible to also use Firestore in offline only mode for free users so that I don't incur costs?
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.
Firebase Security Rules work by matching a pattern against database paths, and then applying custom conditions to allow access to data at those paths. All Rules across Firebase products have a path-matching component and a conditional statement allowing read or write access.
Firebase Hosting uses a powerful global CDN to make your site as fast as possible. Any requested static content is automatically cached on the CDN. If you redeploy your site's content, Firebase Hosting automatically clears all your cached static content across the CDN until the next request.
Note that Firebase Auth web sessions are single host origin and will be persisted for a single domain only. Indicates that the state will only persist in the current session or tab, and will be cleared when the tab or window in which the user authenticated is closed. Applies only to web apps.
Cloud Firestore is an online database that continues to work when you're offline for short or longer periods of time. But it's still primarily an online database, and should not be used as a fully offline database.
One reason for this is that Firestore keeps the local mutations in a separate queue until they've been committed to the server. When a query/read hits the local data, the Firestore client combines the cached reads that it got from the server, with the local mutations. As the queue of local mutations grows, this operation gets slower. As long as the client occasionally synchronizes the data to the server, this slow down won't be significant. But if you use Firestore as a fully offline database, it will become prohibitive over time.
For a good explanation of how the Firestore client works under the hood, have a look at these (long) code comments in the Firestore JavaScript SDK:
the persistence class, which is responsible for storing the data on the local disk
the local store class, which handles (a.o.) the reading from both the local cache and the local mutations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With