Green Cell
Green Cell

Reputation: 4777

Firebase still reading deleted data

I'm using Firebase's realtime database in my Unity project and I ran into a very odd behavior. I'm reading data like this:

_database.GetReference("test").GetValueAsync().ContinueWith(task => {
    if (task.IsFaulted) {
        Debug.Log("Fetch error");
    } else if (task.IsCompleted) {
        Debug.Log("Reading data");
        DataSnapshot snapshot = task.Result;
        if (snapshot.HasChildren) {
            foreach (var user in snapshot.Children) {
                Debug.Log(user.Key);
            }
        }
    }
});

I have my browser open in the Firebase console looking at the data. At first I noticed if I deleted a few fields it was still returning them in my query. So I went ahead and delete all entries to have an empty database, and it's STILL reading the deleted data. What gives? My internet connection is solid, and it's pointing to the right database.

Upvotes: 2

Views: 1395

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

If you have local caching enabled and have read the data before, this is expected behavior the first time you read the data after it's been deleted. The reason is that you're getting the data from the cache, which is then refreshed after the read completed.

What it boils down to is that you shouldn't mix offline caching and Get calls with Firebase's Realtime Database. You'll want to either disable the disk based persistence, or listen for events. In the latter case you'll get two events for the deleted data: the first one with the data from the cache, and the second event with the updated snapshot from the server (which will no longer contain the data).

For more on this and why, see my longer explanation here: Firebase Offline Capabilities and addListenerForSingleValueEvent

Upvotes: 1

Related Questions