Issue
I'd like to use Ionic 4 + Firestore to provide app with offline and live sync capability.
Target deploy to Native App (iOS, Android), electron App (Windows and Mac), PWA.
Is firestore local cache persistent in hybrid app? What type of storage firestore cache using? Will it be something like localstorage, which will be delete by android / iOS from time to time / while low storage.
I'm testing with below code and did enablePersistence, offline mode is working just fine. But it seem that the the it count all documents read per app launch. Example, I'm having 100 documents.
a. While app first launch, it should count as 100 read as it sync all data to local cache.
b. While 2nd time I launch the app, assume, no document was updated, it shouldn't count any read right?
c. Because from my monitoring, the read count increase every time I launch the app.
d. Will it be any possible like, no document was updated, but my code force to fetch data from server then it consume the read count?
Thanks.
getChatMessages(groupId) {
return this.db.collection(`groups/${groupId}/messages`, ref => ref.orderBy('createdAt')).snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
}))
);
}
Solution
I guess you are talking about the offline data, I think your question can be answered with the docs.
1.1. Is firestore local cache persistent in hybrid app? It should since the functionality comes with the client libraries that you should be using into your hybrid app. From this doc:This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. YES, it’s local storage.
1.2. What type of storage firestore cache using?
From this doc: Cloud Firestore is a cloud-hosted NoSQL database. You store data in documents, which contain fields mapping to values.
2. a - You stated: “While app first launch, it should count as 100 read as it sync all data to local cache”, but as mentioned above, Firestore will only load the data that your app is using actively, so mostly your are seeing a subset of your total data (100 documents).
b- Regarding your claim about assuming no document modification, anyway your app will sync the data, which already means a validating request. At this doc it’s stated:
The Cloud Firestore client library automatically manages online and offline data access and synchronizes local data when the device is back online.
c- This claim is correct and points to the sentence I pointed before.
Answered By - sergio franco
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.