Caching response from Netlify function

I’m using Netlify functions to pull products, and collections, from Shopify. Everything works great, and is actually faster than Azure functions which I was using before!

What I’d like to do is cache the JSON response. So in my code frontend I would make a JSON request to<product-id>.json, and if that’s a 404 it will call the Netlify functions.

When the function is called I would like to cache the response and store it in<product-id>.json.

Is this possible?

Short answer would be, “it depends”.

If you decide to do this during runtime (when your site is being used), you’d have to trigger an entirely new deploy as you cannot add a single file to Netlify.

If you’re hosting your frontend elsewhere, you could have a chance to look at their API and features to see if that’s possible.

Finally, if you want to do this, you would have to do this during build time. Generate the JSON files as needed and publish them along with the deploy.

1 Like

Thank you. I have since found out how Gatsby does it, and I think generating at build time is the way to do it. I am hosting on Netlify too.