Cloud Firestore: can I cache read synchronously?

Is it possible to synchronize documents from the cache?

For Android, the documentation gives only an asynchronous example?

 DocumentReference docRef = db.collection("cities").document("SF"); docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { @Override public void onComplete(@NonNull Task<DocumentSnapshot> task) { if (task.isSuccessful()) { DocumentSnapshot document = task.getResult(); ... } } }); 

UPDATE

It seems to me that onComplete is called only when data comes from the server. It seems like it is never called with cached data.

Can anyone confirm?

+5
source share
1 answer

The official documentation gives only an asynchronous example, because synchronous does not exist. All read operations performed either from the cache or via the Internet directly from Firebase, asynchronous servers, and you cannot change this behavior.

What you request can be done on a regular JVM, with the usual Java synchronization primitives, but this will not work on Android.

+3
source

Source: https://habr.com/ru/post/1273235/


All Articles