androidfirebasecachingofflinegoogle-cloud-firestore

Firebase firestore data persistence on mobile(specifically Android)


I'll like to know if it is possible to increase the size of the local cache of the firebase firestore database? Will also like to deepen my knowledge on how firebase firestore offline

data persistence functions on mobile( android specifically). Let me explain my use case and you evaluate if firebase firestore is the route to go for me.

I require a local database that can be synced averagely after every 24 hours and I require it to function offline and persists it's data. The main use case is this: I have a messaging feature integrated into the application and just as everyone expects to see his messages he's got to send and receive before he was disconnected that is, just as even when one is disconnected, he still can see his different conversations on whatsapp even after a phone reboot, that's how i expect my application to follow and I want to know if firebase firestore local cache offers me this possibility of persisting the cache even after phone reboot without having to connect to the internet? I do expect a lot of reads from the local cache but not that of writes while offline.

To summarize my question, can the local cache persists changes that have been made while the phone was offline even after phone reboots without any connection to the internet? Thank you all for your answers and time taken to read this in advance. Please, do include some helpful links to tutorials showing how to use it if you do know any of them.


Solution

  • Edit: 2023-13-11

    Nowadays there is a default cache size threshold which is set to 100 MB. You can also configure the "setCacheSizeBytes" for a custom threshold but the minimum is 1 MB.


    The size of the local cache depends on the size of the storage of your device. If you want to increase the size of your local storage, then you just need to free some space or buy new hardware. There is no limitation regarding the maximum size that can be stored on your device.

    Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. So, Cloud Firestore persists the data you write on a device to a local database. So the next time you start the application, it will indeed be able to read that same data, even when the device has never been connected to the Firebase servers. And as an answer to your question, yes it can.

    But don't use Cloud Firestore as an offline-only database. It is really designed as an online database that came to work for short to intermediate periods of being disconnected. While offline it will keep a queue of all your write operations. As this queue grows, local operations and app startup will slow down. Nothing major, but over time these may add up. But remember, all these operations will persist even if you restart the device. You not gonna lose any data.