iosswiftfirebasegoogle-cloud-firestore

Firestore iOS: caching offline writes only


My database holds a large number of objects, so for performance reasons I've needed to disable persistent caching:

let settings = FirestoreSettings()
settings.cacheSettings = MemoryCacheSettings()
Firestore.firestore().settings = settings

With caching disabled, will offline writes still be saved and resumed later across app launches? Or will they be lost when quitting the app?

My goal would be to disable caching of the full dataset, and only cache offline edits.


Solution

  • The documentation about offline access doesn't say anything about changing the effects of offline writes, only offline reads. The code you're showing therefore only affects the read behavior. Write behavior stays the same (meaning that offline writes continue to accumulate until the app is able to come back online and the queue is able to clear).

    Even if you disable the offline cache entirely, the documentation still clearly states:

    Write operations are queued until network access is re-enabled.

    Think of it this way: It would be seriously bad for any app to fool the end user into thinking their changes were committed, only for them to come back later and realize that everything was actually lost. Disabling write persistence would risk precisely this situation, which is why it's not an option.