The tests we have run by activating the edge functions cache have not worked.
I leave you a link to a repository with the example:
And link to the deploy:
Theoretically the function should cache the response and not return a new response each time a request is send.
Could you tell us where we are doing wrong?
@existo I see no
cache-control header in the response?
The documentation here: https://docs.netlify.com/edge-functions/optional-configuration/#configure-an-edge-function-for-caching
There are two parts to configuring an edge function for caching:
If you do one part but not the other, your edge function responses will not be cached. They will use the default behavior and every request to the edge function will invoke the function for a fresh response.
The next relevant part being:
@nathanmartin Thank you very much
Now I understand. I have updated the example and everything works as expected.
It would be much better to be able to do all the configuration from the netlify.toml configuration file.
For example, we work with Astro and there is no option to modify the headers of the edge function generated in the build.
If we could configure the cache behavior from the netlify.toml it would not be necessary to wait for an implementation of this functionality in Astro.
Is it not possible to solve the configuration of the headers in another way? Without touching the function code?
I couldn’t say, I’ve never used Netlify’s Edge Functions, I just consulted the documentation to answer your original question
If system A requires X thing to be done, and system B doesn’t do it, that’s hardly the fault of system A… could it be improved, sure, but so could system B,
Finally, everything is very simple in Astro.
It is only necessary to configure in the netlify.toml file the edge function and in the template to render include the header rewriting…
Astro.response.headers.set('cache-control', 'public, s-maxage=3600')
I leave the comment in case someone has the same problem.