Do Firebase Realtime Database uses cache - flutter

Right now i'm using Firebase Realtime Database, is there a way to see if i'm reading data from the Realtime Database or from cache ?(i want the same way like .isFromCache() from https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/SnapshotMetadata).
i read from other stackoverflow question Does Firebase cache the data?, that when i use once(), it clears the cache. is there any way to track where i'm reading the data ?

There is no way in the Realtime Database API calls or results to see whether a resulting snapshot came from the cache or from the server.
The isFromCache method from the Firestore API is not available on Realtime Database. It also doesn't necessarily do what you expect it to do, but that seems besides the point here.

Related

Determine source of Database Event in Firebase RealTime Database and Flutter

I have a Flutter app using Firebase Realtime database. I have created subscriptions to add, change, and delete for a node.
I would like to determine if the DatabaseEvent received for these subscriptions was generated by the local application, or by something else (for example, a direct edit using the Firebase Console.)
I know I could probably store some information when I issue the database add, change or delete, and then when I receive the event compare to see if the same item referenced, but I was hoping to see if there was some information in the Event itself (or somewhere else) that would tell me this.
Anyone have an idea?
I have examined the DatabaseEvent object returned when the subscriptions fire, but I don't see any information that could help.
firebaser here
There is nothing built in for this in the Firebase Realtime Database SDK or in any of its other APIs. If you want to know the source of the data, you'll have to track it yourself.
One of our early demo apps for a shared whiteboard held a list of the push keys for all its pending writes, so that it could filter those in its listener (as it had already drawn the local strokes before even sending them to the database). But there are many other valid approaches for this too.

Create a new user and add new documents in Firebase database and add image in storage

I'm developing an app with flutter and I want to add information about the user account in the firebase database when I create it and add its profile image in the storage.
And I want to be sure that either all of the operations succeed, or none of them are applied like transaction!
Can you please tell me how doing it?
There is no way to perform a transaction across multiple Firebase services, such as Authentication and the Realtime Database here.
You'll have to assume that the data can get corrupted and define a strategy how to deal with that both in the code that consumes the user data, and possibly in (server-side) code that performs a periodic cleanup.

If I use firestore offline to store the data for the chat app, do I still need sqlite, flutter

I wanna create a chatapp for my friend, and now remote serve I will use firestore and locally sqlite, but I realized it is default for firestore to save data offline, so my question is I have some data like message, or sending setting for the app, is it ok just to save them in firestore offline which seems automatically and no extra costs.
It depends on what you want or need.
If you want to use the offline persistance only for storing in case internet is not there at all. Firebase supports that out of the box. But you need to keep in mind to do you calls carefully. Because on a slow internet connection, if you tell the Firebase access to wait for the online behavior. It will not be using the local first and you might not be able to show the data. Check the question here
Also if you want to use the offline persistance from Firebase, be mindful that the data size has a default of 40 megabytes of limit. You might assign that by your self. You can check this link
BUT, if you want to have heavy data manipulations and have more control over your data SQLite is more suggested.
My opionion: I think Firebase Offline persistance would be enough for you, so go for it.

Avoid fetching the same data from Firestore over and over again whenever the app starts

I am sorry, if it is a stupid question. I started to work with a Firestore db in a SwiftUI iOS App. Since I will be charged for every read/write/delete I try to avoid to read-in a snapshot with tons of documents (e.g. messages in a messenger app) every time the user starts the app.
I wondering what is the normal way to handle that? Do I have to write/save the messages locally into a sqlite or realm to fetch them at the next time from the internal db (on the Firestore side I create a query to read/load only documents that are newer than the last locally saved message)? Or does the Firestore (Firebase) has a built-in solution e.g. the cache?
I think you've already answered your question. You can save documents (messages) locally so you don't have to fetch them from Firestore every time (and only fetch the new ones). Firebase can cache data locally, but only temporarily. Saving the data using sqlite, realm, or even CoreData is a wise move.

Do I need cache if using CoreData

First of all I'm new in ios/swift...
I need to have offline mode of my app.
I'm using Alamofire for all networking getting json, convert to objects and save into the DB (Core-Data). Wanted to know do I need to have additional cache in between (like: Haneke, or DataCache) in case no internet connection or getting from CoreData?
Is DB request fast/convenient enough?
CoreData is very fast (if correctly used). I don't believe it would be necessary to have an additional cache layer.
It would be just a duplication of data that you already have stored in your DB.
By the way all depends from your project use cases. I would not rely on temporary cached data if my app must work without internet connection.
To give you an idea of core data performances so that you can choose what works best for you: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/Performance.html