Reputation: 13
We work on an hybrid app built with Capacitor + Angular + Firestore that targets iOS devices.
As we are building the app like a web one, we don't use any Firebase or Firestore capacitor plugin, we rely entirely on Firebase Web Modular SDK.
Our goal is to disable offline cache in our app as it causes consistency issues for our users.
In the dedicated documentation page from Firebase, we can read :
For Android and Apple platforms, offline persistence is enabled by default. To disable persistence, set the PersistenceEnabled option to false.
For the web, offline persistence is disabled by default. To enable persistence, call the enablePersistence method. Cloud Firestore's cache isn't automatically cleared between sessions. Consequently, if your web app handles sensitive information, make sure to ask the user if they're on a trusted device before enabling persistence.
The problem is that PersistenceEnabled
seems to be available in the Firestore Swift API that we don't use, and Web API seems to only provide a way to enable offline cache which is disabled by default on Web. As we use Web API in an iOS context, we can't figure out how to disable offline cache in this case, as Web API does not seem to propose a disablePersistence
equivalent method.
I can affirm that offline cache IS actually effective when we deploy our app on iOS, whereas it is not the case when we run the web app in a browser.
The only alternative we have now is to replace all calls to getDocs
by getDocsFromServer
, and to handle the 'unavailable'
error manually. And we hadn't yet study the case of methods that writes data in Firestore.
Upvotes: 0
Views: 74
Reputation: 599706
If you're using the Web SDK, caching is already disabled.
The documentation is incorrect here:
So if you use the JavaScript SDK, it will never enable caching by default - no matter platform platform you run it on.
You might want to leave feedback on the documentation page where you found this quote.
Upvotes: 0