How to save firestore requests by using Http cache-control?

99封情书 提交于 2019-11-29 11:35:26

Firestore does not make requests in a way that HTTP Cache-Control headers would apply.

However, the protocol includes a notion of a resume token which allows entire queries to be resumed at a later time, possibly avoiding the retransmission of any unchanged documents that match the query.

If you enable persistence in your web app, Firestore will cache the documents and resume tokens in a local IndexedDB for you. If you come back to a page later, it will use the resume token transparently and avoid retransmission.

Note a pricing caveat:

If the listener is disconnected for more than 30 minutes (for example, if the user goes offline), you will be charged for reads as if you had issued a brand-new query.

So, to specifically address your question. If:

  • you have persistence enabled,
  • the underlying data hasn't changed,
  • a user loads page A, and
  • loads page A again 5 minutes later

Then Firestore will request the data for the page but the server will essentially respond that nothing has changed: no documents will be transferred and there will be no charge to confirm that.

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