get
By default, get() attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via the Source parameter.
If you are online, get()
will attempt to check the server for latest data (which takes between 300ms - 1500ms).
If you are offfline, get()
will return result from cache (probably immediately).
You could specify Source.CACHE.
Causes Firestore to immediately return a value from the cache, ignoring the server completely (implying that the returned value may be stale with respect to the value on the server). If there is no data in the cache to satisfy the get() call, get() will return an error and get() will return an empty QuerySnapshot with no documents.
addSnapshotListener
- DocumentReference.addSnapshotListener
- Query.addSnapshotListener
- Get realtime updates with Cloud Firestore
Based on the following posts (I couldn't find any official documentation)
- https://stackoverflow.com/questions/46675765/firestore-document-get-performance
- https://stackoverflow.com/questions/50289668/how-to-make-getting-data-faster-from-firebase-firestore
addSnapshotListener
will return result immediately if there is a local cache, and will invoke again if the local cache differ from the server. Technically, addSnapshotListener
shall return result faster than get
if a local cache already exist.