I am currently writing a react + Firebase project for learning purpose, and I am wondering which approach should I take to read from firebase efficiently.
Say I have this read only collection called product where it contains around 5000 documents hence when user access my react app then it would be charged for 5000 reads per access.
Source : Cloud Firestore: How is read calculated?
Since this would consume the read counts rather quickly if user spams refresh to react app, is there any proper way to read the data from firebase firestore ?
Store product information in localstorage
- Once react app successfully loads the data, proceed to save product information into localstorage to avoid unnessary loading in the future.
use SOURCE.CACHE from firebase
- The idea is similar to localstorage, but instead of using localstorage we can make use of SOURCE. CACHE to retrieve data from cache by forcing firebase into offline mode. Source : https://firebase.google.com/docs/firestore/manage-data/enable-offline
- How to avoid unnecessary Firestore reads with Cache, this is the closest to my current query but my collection is only read only data and will not be updated I might not be able to add snapshot listener. Please kindly let me know if I have misunderstood the functionality.
limit read query ?
- Limits a fixed amount of documents return of each load, but at the end of the day I will still have to load the full set of documents hence I am quite skeptical of this.
This is what I can think of so far, please kindly let me know if there is any golden standard or procedure in the your app building design.
Thank you.