0

I have been working on my React + Firebase app for the past year and I've come to the realization that I will need a caching layer to avoid unnecessary Firestore costs.

My idea for the flow is as follows:

  1. Always try to fetch from IndexedDB first; if there is no data inside for the specific queried collection, move to step 2
  2. Fetch data from the server, store it inside IndexedDB, and server it to the UI
  3. Use Firebase's onSnapshot() functionality to keep the data inside IndexedDB fresh

I do not have much experience with caching layers, but the only potential drawback of this strategy that I see is that I will need to keep a process constantly running in the background that listens to all the collections inside the Firebase DB to keep the data inside IndexedDB fresh.

Is this a viable strategy when it comes to making sure the user always sees fresh data? What are the potential drawbacks?

I know there are other strategies such as paginating queries but I find it cumbersome and not that intuitive due to my app's architecture.

3
  • Firestore already has caching built-in: firebase.google.com/docs/firestore/manage-data/enable-offline, which you can simply enable on web like shown here: firebase.google.com/docs/firestore/manage-data/…. Did you consider using that? Commented Oct 28 at 15:00
  • Thanks for your question! Stack Overflow is now running an experiment that allows opinion-based questions. Please re-ask and choose one of the new question types (tooling recommendation, best practice, advice) in the ask question form. We’ve just added you to the experiment group, so that form field should now be visible to you! Commented Oct 28 at 18:29
  • @FrankvanPuffelen that is not really what I am looking for, though. Commented Oct 29 at 10:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.