Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase keepSynced(true)

What are the trade-offs when I use sync on several paths in my Firebase database?

databaseRef.keepSynced(true);

I never clear the sync from these paths.

In addition, I might call databaseRef.keepSynced(true); several times on the same path. Is t a problem?

I'm also using

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

So what do I "pay" for this sync in terms of battery life, memory issues?

like image 460
user2924714 Avatar asked Jan 05 '17 06:01

user2924714


People also ask

Is it possible to use firebase offline?

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 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.

Does firebase use Internet?

While the device is offline, if you have enabled offline persistence, your listeners will receive listen events when the locally cached data changes. You can listen to documents, collections, and queries.


1 Answers

When you use the keepSynced() method, you're telling Firebase to download and cache all the data from databaseRef. I hope databaseRef isn't the root Reference of your Database because if it is, you're downloading your entire database and this is not a good practice.

You should use keepSynced() to cache nodes that are really necessary for your app to work offline.

You will probably be wondering how is it different from setPersistanceEnabled(true). Well, setPersistanceEnabled(true) only caches data when there is a Listener attached to that node (when the data has been read at least once).

On the other hand, keepSynced(true) caches everything from that node, even if there is no listener attached.

like image 74
Rosário Pereira Fernandes Avatar answered Oct 20 '22 10:10

Rosário Pereira Fernandes