Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase offline capabilities as cache

I am wondering whether it is a sound strategy to use the firebase offline capabilities as a "free" cache.

Let's assume that I am in activity A, I fetch some data from firebase, and then I move to activity B, which needs the same data. If the app is configured with setPersistenceEnabled(true) and, if necessary, also with keepSynced(true), can I just re-query the same data in activity B, rather that passing it around?

I understand that there is a difference between the two approaches regarding reading-from-memory and reading-from-disk (firebase offline cache). But do I really get rid of all the network overhead by using firebase offline?

Relevant links:
Firebase Offline Capabilities and addListenerForSingleValueEvent https://groups.google.com/forum/#!msg/firebase-talk/ptTtEyBDKls/XbNKD_K8CQAJ

like image 315
talosdev Avatar asked Aug 04 '16 23:08

talosdev


People also ask

Can I use Firebase as offline database?

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache.

Does Firebase have a cache?

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.

Why you should avoid Firebase?

With Firebase, you can't deal easily with data-migration like you can do with a simple SQL database. Firebase uses JSON and there are almost no features SQL features, so you wouldn't be able to migrate from the existing database easily. If you're managing large amounts of highly structured data.

Does Firebase use localStorage?

Francisco Mateo. I noticed while configuring my Vue app with Firebase that upon successful authentication, Firebase will set the user in localStorage.


1 Answers

Yes, you can easily re-query your Firebase Database in each activity instead of passing data around. If you enable disk persistence, this will be a local read operation. But since you attach a listener (or keep it attached through keepSynced()), it will cause network traffic.

But don't use Firebase as an offline-only database. It is really designed as an online database that can work for short to intermediate periods of being disconnected. While offline it will keep queue of write operations. As this queue grows, local operations and app startup will slow down. Nothing major, but over time these may add up.

like image 125
Frank van Puffelen Avatar answered Oct 20 '22 19:10

Frank van Puffelen