Netlify Function response caching

Relying on browser cache to persist data is not a good option in my personal opinion.

But in case of your actual problem, I’d suggest an entirely different approach than caching. I’d personally use an external database and fetch and store data into it the first time it’s requested. I’ll also save the timestamp of the request. For any subsequent requests, I’d query the database for the ready made response and check the timestamp. If it’s well within a week or so, I’d just pass the response from the database or if not, I’d query the API. This way, you don’t need to rely on browsers to persist the data, you can persist it yourself and have complete control over it.

About why iOS browsers don’t cache - I’m sorry that’s a question for the browsers. A server can send some response, but it’s up to the browsers how they handle it. I’m sorry I don’t have a better answer for that.

Function responses are not cached in the CDN, so the requests that you’re seeing are all uncached.

I have seen some weird caching behaviour on function responses by browsers in the past. I was testing with Netlify CLI and had setup a redirect in the function. I changed the code but was still being redirected to the previous destination. After spending a lot of time debugging why, I found it was merely a cache issue as the redirect worked fine in incognito.

1 Like