I retrieve 10 keys each time from my sorted DB.
FirebaseDatabase.DefaultInstance.GetReference("CarsForSale/")
.OrderByKey().EndAt(lastSavedKey).LimitToLast(10).GetValueAsync()
It works fine. But when new items are added to the database, I can't retrieve those new values unless I reset the app.
If I don't use the query .OrderByKey().EndAt().LimitToLast
, I do get the new keys from the DB without resetting the app
My guess is when I query the value at a location, it locally caches it.
My solution for a while was using KeepSynced(true)
and it worked.
DatabaseReference dtr = FirebaseDatabase.DefaultInstance.GetReference(path);
dtr.KeepSynced(true);
dtr.OrderByKey().EndAt(lastKey).LimitToLast(10).GetValueAsync()
But it made my app very slow because that syncs and caches the entire DB reference. So instead I tried to apply KeepSynced only on the query of every sorted 10 keys but it doesn't make sense.
What can I do to make sure when I query keys from the DB to get the latest keys without having to restart my app or make it slow with caching?