'What is the expected behaviour with Firestore cache disabled?

Context: My users need to see the same data.

Example: Admin user deletes item from customer order. Admin user is offline so change happens in cache only. Customer thinks he is still getting his product. Balance due, customer expectations, etc. obviously all out of sync.

Persistence is turned off:

await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
FirebaseFirestore.instance.settings = const Settings(persistenceEnabled: false);

Why can I still delete a document locally, or write to cache? Are there any other options? Is this setting working as it should?

The only two workarounds I can find from reading articles and other questions is creating callables to cloud functions, and using a transaction - this is obviously not as fast. And is using transactions this way good practice?

I just don't want to be doing something else and find out I am doing something wrong with this cache setting as its not working as expected:

https://firebase.flutter.dev/docs/firestore/usage/ "This functionality is enabled by default, however it can be disabled if needed."

What I would like is for it to just throw if cache is false.

Thank you



Solution 1:[1]

Setting persistenceEnabled to false disabled the persistent cache that Firestore uses to caching data and keep pending writes between page/app reloads. But even when this is set to false, the Firestore SDK will keep all pending writes and data you have active listeners on in memory. This allows it to work in the situation of spotty network connections, which is quite common.

There is no way to disable the in-memory cache of pending writes.

Possible workarounds are to either detect the no-network situation yourself, and disable the functionality you don't want to allow, or (as you said already) use a mechanism that inherently requires a connection, such as a transaction or calling a Cloud Function.

All of these lead to a worse user experience though, so I recommend considering whether disabling the operation is really needed, or if there's a way to work with Firestore's model rather than against it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen