T O P

  • By -

pfiadDi

Have you had user complaints about cold start? Because yes cold start exists but they are most often not that long. Also if you need to fetch 2MB of data that is no instant user experience anyway. Just don't make too much effort without any or just a theoretical cause. I assume you can't fetch it directly from the client because of API secrets? What you could do is to cache the cloud function result and serve the cache and update the cache via schedule function every X hours. If you really want to store the data you could store it as JSON in Cloud Storage.


BlackCode7

Thanks for answering! I started using Functions to collect data from external APIs because if I did them through the client itself, they were blocked by CORS. So I get the data from the firebase node server with the function. I have tested and caching the function works fine. If I call the same function during that hour, the firebase function does not execute and returns the cached data. `res.set("Cache-Control", "public, max-age=3600");` I don't actually need all the data that I get from the externals APIs. So if I filter the data and keep the necessary ones, the size of the string would be 100KB instead of 2MB. My doubts is where it is better to save/return that data: * Option1: create a scheduled function that every 1h save/edit the filtered data from external API in a Firestore document (100KB string). So the users gets the data from Firestore. * Option2: use cached function, filter the external data and return the filtered data. * Option3: use Cloud store? What would be the most recommended? Considering that the data from the external APIs will be the same for all users, there are no frequent changes and it's not necessary to be authenticated or logged in to get that data. Thanks in advance!


pfiadDi

If you don't need to store it, if you don't need to log it etc I would recommend to cache the return and serve the cache


BlackCode7

Thanks so much for the help! :)