Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Firebase Firestore in offline only mode [closed]

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?

like image 202
brucemax Avatar asked Feb 19 '18 18:02

brucemax


People also ask

Can firestore be used offline?

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.

What are the restrictions in Firebase?

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.

Does Firebase cache data?

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.

Is Firebase persistent?

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.


1 Answers

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.

like image 115
Frank van Puffelen Avatar answered Nov 03 '22 20:11

Frank van Puffelen