Learner123
Learner123

Reputation: 73

Caching in firebase

I have my app hosted in firebase and using cloud functions to fetch data from a third-party API. This cloud function is HTTP triggered and runs whenever client-side requests data. I want to reduce cloud functions calls (as it is currently on Blaze plan), so thinking to add caching in my app.

  1. What are the caching strategies I can use on the client (web browser) as well as server-side (Node.js)?
  2. Overall I want to reduce cloud function calls to minimize costs, so that on every client request, cloud function doesn't need to be called, instead the client can fetch data from cache.
  3. Should I use firebase real-time database for storing data from third-party API and update this in firebase over a period of time, so that data is up-to-date? Data on the third-party side doesn't change frequently.
  4. Whether fetching data from real-time database (as mentioned in point 3 above) instead of cloud function calls would eventually reduce costs?

Upvotes: 2

Views: 1674

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598887

If you host your Cloud Function behind Firebase Hosting, you can write a cache header in every response and manage the cache behavior of Firebase Hosting that way. Allowing the content to be served from Firebase Hosting's CDN may significantly reduce the number of times your Function gets executed, and thus its cost.

Upvotes: 5

Related Questions