existo
June 22, 2023, 10:09pm
1
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:
https://test-cache-edge-function.netlify.app/date
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?
Thanks
@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
Says:
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:
https://docs.netlify.com/edge-functions/optional-configuration/#customize-cache-behavior
existo
June 23, 2023, 12:13am
3
@nathanmartin Thank you very much
Now I understand. I have updated the example and everything works as expected.
Solved.
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?
Thanks
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,
existo
June 23, 2023, 6:50am
5
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.
2 Likes