0

I have a ListenerForSingleValueEvent that checks for a particular value in the database before a particular operation can be carried out. But because .setPersistenceEnabled is true, it uses the value from the disk cache which could be sometimes wrong and not updated and causes the user to perform the task even though the user should not be able to.

I could set .setPersistenceEnabled to false, but I have a chat feature and it would be very user unfriendly to reload messages each time the user opens the app. Is there a way I could set .setPersistenceEnabled for only some particular Database References and reload all other references each time or vice-versa, i.e, .setPersistenceEnabled for all Database References and reload particular references each time. Thanks for the help.

Grimthorr
  • 6,856
  • 5
  • 41
  • 53
Ace Falobi
  • 741
  • 1
  • 8
  • 25

1 Answers1

0

Sounds like you might be able to use Query.keepSynced():

By calling keepSynced(true) on a location, the data for that location will automatically be downloaded and kept in sync, even when no listeners are attached for that location. Additionally, while a location is kept synced, it will not be evicted from the persistent disk cache.

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158