Matthew Johnson
Matthew Johnson

Reputation: 93

Instantly access Firestore offline cache in Kotlin

I would like to access Firestore cached data. I am able to do so using the following code:

db.collection("users").document(userID).get(Source.CACHE)
    .addOnCompleteListener { task ->
         // Access data here
    }

However, this gets data asynchronously (but almost instantly). I would like to return this cached data in a synchronous function. Is there a possible way to do this?

Upvotes: 0

Views: 43

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

While data access from the cache is local, it still requires reading from disk, which may be a lot slower for some of your users than you are experiencing.

There is no way to get data from Firestore (cached or not) with a synchronous call. You will have to deal with the asynchronous nature of the API.

Upvotes: 1

Related Questions