does firebase charge for retrieving docs from firestore js sdk cache

后端 未结 1 806
囚心锁ツ
囚心锁ツ 2021-01-19 06:37
  • I am using the firebase JS SDK, with offline persistence enabled. This will automatically cache my retrieved documents inside the JS SDK.
  • I perform this query
相关标签:
1条回答
  • 2021-01-19 06:53

    does firebase charge for retrieving docs from firestore js sdk cache?

    No it doesn't. If a read is fulfilled from the local cache, it is not charged as a server-side read.

    But your code has two get calls:

    // once
    firebase.firestore().doc('path/to/doc').get()
    // twice
    firebase.firestore().doc('path/to/doc').get()
    

    And in this case, the Firestore client has no way to know whether the document was changed between these two calls. So it has to call to the server to determine whether the document was changed, which is (or at least may be) a charged read.

    If you need to know the current state of a document in multiple places in your app that execute close to each other (time wise), you should keep an onSnapshot listener on that document. This ensures that the local cache is always up to date at a minimal cost.

    0 讨论(0)
提交回复
热议问题