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

☆樱花仙子☆ 提交于 2019-12-29 08:06:08

问题


Let's say i have a web/mobile app running firebase firestore database.

My app is set to serve mostly dynamic content fully stored in firestore.

So we are talking about caching dynamic content

If a user load Page A, it's will make 1 request to firestore (for example). If this user go to Page B and then go back to Page A 5 minutes later, i don't want the app to make another request if the content has not changed.

I heard about http cache-control headers but my concern is. If the cache control go check firestore to learn if the content is still the same, will this operation be counted as a request by firestore ?


回答1:


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.



来源:https://stackoverflow.com/questions/46579285/how-to-save-firestore-requests-by-using-http-cache-control

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