0

Generally, when I set a value to the Firebase-realtime-database, the SDK first writes the data into a local cache, and then it forwards the data to server. When I'm listening to the same node, listeners will be triggered even before data reaches the server.

But what if I made a write like this:

databaseReference.setValue(ServerValue.TIMESTAMP)

and then listen there like this:

databaseReference.addListenerForSingleValueEvent(object : ValueEventListener {
    override fun onDataChange(snapshot: DataSnapshot) {
        snapshot.getValue<Long>()!!
    }

    override fun onCancelled(error: DatabaseError) {}
}

I have confusion in this because timestamps are written by server. So how can it return correct data in local cache?

Sourav Kannantha B
  • 1,271
  • 1
  • 5
  • 19

0 Answers0