Reputation: 15
How can I disable sync for a particular firebase collection once it is loaded? Unless it's forced it should not again check the server.
Suppose I have a user collection. i would like to read the user values from server only when the user logs in. I don't expect updated values for user collection until the user logout and sign in again.
Is there a way for it?
Upvotes: 0
Views: 466
Reputation: 599591
If you want to force the Firestore client to read from its local cache, you can :
get()
calls with SourceOptions
to force getting documents from the cache only.disableNetwork
to disable all network access.Note that neither of those is a great option, as Firestore is primarily a cloud-hosted database that can continue to work while you're offline for short of medium time intervals. If you want to only use Firestore to periodically synchronize data, I'd recommend using Doug's first approach and use a separate local database for you local needs.
Upvotes: 0
Reputation: 317712
It's not possible to "disable" synchronization on a specific collection. The SDK will synchronize everything all of the time with the same behavior. If you want to load data only once, you will need to write some code to handle this situation. You could:
If you must only read data once, and use that data reliably forever, you should implement the first option.
Upvotes: 1