How to bypass the Firebase cache to refresh data (in Android app)?

后端 未结 7 1896
孤街浪徒
孤街浪徒 2020-11-30 21:48

On an Android application which must works offline most of the time I need, when it\'s online, to do some synchronous operations for i.e. :

User myUser =  My         


        
7条回答
  •  Happy的楠姐
    2020-11-30 22:45

    My Solution was to call Database.database().isPersistenceEnabled = true on load up, then call .keepSynced(true) on any nodes that I needed refreshed.

    The issue here is that if you query your node right after .keepSynced(true) then you're likely to get the cache rather than the fresh data. Slightly lame but functional work around: delay your query of the node for a second or so in order to give Firebase some time to get the new data. You'll get the cache instead if the user is offline.

    Oh, and if it's a node that you don't want to keep up to date in the background forever, remember to call .keepSynced(false) when you're done.

提交回复
热议问题