Valentin
Valentin

Reputation: 5598

Firestore: Totally disable cache for read and write

I use Firestore (from Firebase) and I have tried, without success, to disable the usage of the cache.

Here is my problem. If I disconnect my device from the internet and that I execute this ...

getFireStoreInstance()
    .collection(PATH)
    .document(myObject.id)
    .set(myObject)
    .addOnCompleteListener( ... )

or this ...

getFireStoreInstance()
    .collection(PATH)
    .batch()
    .update(...)
    .commit()

... nothing happens (which is good because I don't have any internet connection). However, as soon as I reconnect my device to the internet, the completionListener is called to notify me that the action has been completed.

What I would like is that, when my device does not have access to the internet, the action fails and that the completionListener is called with failure. Is that possible?

Of course, I have tried the following code (from Firestore doc) but it looks to have no effect for writing (it has effect for reading though).

val settings = FirebaseFirestoreSettings.Builder()
        .setPersistenceEnabled(false)
        .build()

FirebaseFirestore.getInstance().firestoreSettings = settings

Thank you in advance

Upvotes: 3

Views: 1112

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317372

Listeners don't ever fail due to network connectivity, and you can't change that behavior. They always silently retry. The whole point of having a resilient SDK like this is to prevent perceived disruption in your app when its network connection is flakey - and that happens a LOT with mobile apps.

If you require for something to fail due to lack of connectivity, make an HTTP (or callable) endpoint with Cloud Functions, and call that directly. The call will fail if the HTTP socket can't connect.

Upvotes: 1

Related Questions