Firestore + Ionic Angularfire Read Count & Cache Persistent

情到浓时终转凉″ 提交于 2019-12-11 14:30:09

问题


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.

  1. 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.

  2. 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 };
      }))
    );
  }

回答1:


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.



来源:https://stackoverflow.com/questions/58184612/firestore-ionic-angularfire-read-count-cache-persistent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!