0

I would like to know how Firebase Realtime Database download works in below conditions:

  1. Offline persistence is enabled
Database.database().isPersistenceEnabled = true
  1. App is launched first time. Read the data from the same node in the below order
Database.database().reference().child("foo").child("uid1").observe(.childAdded) { snapshot in
print(snapshot)
}

Database.database().reference().child("foo").child("uid1").observe(.value) { snapshot in
print(snapshot)
}

What I observed are:

  1. 'childAdded' observer will print the fresh data sequentially
  2. 'value' observer will then bring the same but at once.

My question is, will the data the value observer brings be from cache in this occasion?

I've seen a few of similar questions(link1, link2) but I am not 100% sure that it is from cache and not fire the server to send the duplicated data. Any help would be appreciated.

Matthew So
  • 75
  • 1
  • 2
  • 8
  • If the data is present in the local cache, it'll be served from the cache. But this sounds like a [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem): what is the actual problem you're troubleshooting, and can you show an [MCVE](http://stackoverflow.com/help/mcve) for that? – Frank van Puffelen Jan 31 '23 at 15:01
  • A couple of things; first, we need clarity on the issue per the above comment. Second, the *order* of your code is not relevant to how/when data is being read. Firebase is asynchronous and Firebase closures can resolve in different orders at different times. However, in this case a points; .childAdded events will fire before .value events - more importantly, are you wanting /foo/uid1 to generate an event every time *anything* changes in that node? – Jay Jan 31 '23 at 17:18
  • Sorry Frank and Jay for the late late reply. Although I wasn't able to answer your questions your comments helped me to go forward. Thank you. – Matthew So Jul 26 '23 at 16:08

0 Answers0