My app uses Firebase to sync and restore data. I use the setValue:withCompletionBlock:
method to insert, update and delete Firebase objects. This method is called whenever there is a CoreData save, thus syncing all my local changes to Firebase
- (void) setValue:(id)value withCompletionBlock:(void (^)(NSError* error, Firebase* ref))block;
Now syncing uploads all the local data to firebase, while restore replaces the local data with firebase data.
- (void) observeSingleEventOfType:(FEventType)eventType withBlock:(void (^)(FDataSnapshot* snapshot))block;
I observe FEventTypeValue
and use the FDataSnapshot
to get data from the Firebase and restore the local data.
So everything works perfectly for me until I set persistence
to Firebase.
[Firebase setOption:@"persistence" to:@YES];
Now when persistence
is on, when I update, say insert an object into Firebase, and then restore, the data before the insertion is restored. ie the newly inserted object is not restored. However if I restore again, the inserted object is restored. The same thing happens when an object is deleted. The deleted object reappears when I restore for the first time and vanishes when I restore again. I can see that the Firebase objects are inserted and/or deleted correctly through the Firebase data view.
I'm not sure what I'm doing wrong here. I only have issue when I restore. I think the Firebase cache is causing this restore issue. I'm thinking of clearing the Firebase cache before I restore. My question is
- Is clearing the cache before a restore a good method?
- If yes, how to clear the Firebase cache?
- If no, can you suggest me the best method to restore data.