-1

I was reading this question and I have a concern.

What Doug says in the answer makes sense: the point of persistence is to cache documents so future reads are not required. Once the document is updated (from the device) in the future, the cache is also updated and you're good, it all works, beautiful.

What if the document is updated off-device?

Say you have a user document with a name field, it's value is "Doug". This document is cached on your phone, on your app.

Then our user goes to the web version of your app and changes the name to "Stevenson". Your phone will never know about it, will it? Your phone's app will never update that document on its cache cause it doesn't know it has been updated, will it?

Doesn't this mean offline persistence shouldn't be used with multi-client apps? Or is there a way around this?

Note: I am not talking about the phone being offline. I'm talking about the phone online. Even being online, from my experimenting, the cache isn't updated. The cache is only updated when the document is from the device.

E_net4
  • 27,810
  • 13
  • 101
  • 139
  • "from my experimenting, the cache isn't updated" Please update your question to include the [minimal, complete/standalone code that reproduces the behavior that you're asking about](http://stackoverflow.com/help/mcve). Without that it will be hard to answer any questions about that behavior. – Frank van Puffelen May 09 '19 at 14:17
  • You can create your own strategy. This this answer https://stackoverflow.com/questions/47843218/offline-issue-with-firestore-vs-firebase/65667256#65667256. – mahdi shahbazi Jan 11 '21 at 12:58

1 Answers1

1

Your phone will never know about it, will it?

That's right, since the phone is offline it doesn't know what is going on the server.

Your phone's app will never update that document on its cache cause it doesn't know it has been updated, will it?

Will never update the document as long as it stays offline. When is coming back online, the phone will get fresh data from Firebase servers.

Doesn't this mean offline persistence shouldn't be used with multi-client apps?

This is how it's actually working.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Are you sure the cache will update when the phone comes back online? Those are not the results I'm seeing right now. The cache doesn't update until the document is updated **from the device**. Could it be a bug? – Daniel Valderrama May 09 '19 at 11:37
  • "Are you sure the cache will update when the phone comes back online?" I'm positive. The cache will be updated once you read the data from the server. With other words, you first need to get online so your phone can be synchronized with Firebase servers. Be also sure to have the correct security rules. – Alex Mamo May 09 '19 at 11:43
  • @DanielValderrama To clarify; a device will only update/cache the data it's observing. So if an app has a *.childAdded* observer attached to a /users node, when the device goes online any users that had been added within the users node will be updated on the device. However, changes that occurred in the /posts node will not because there was no observer on the /posts node. Keep in mind the intention of offline persistence is to keep your app working when you are *temporarily* disconnected from the internet; going through a tunnel for example. Firebase is an *onliine database*, not offline. – Jay May 09 '19 at 14:25
  • @Jay Thanks Jay for this very helpful comment. – Alex Mamo May 09 '19 at 14:37