Website team name: iamsterdam
Website URL: www.iamsterdam.com
The website is built using NextJS. I’m using a nextJS api endpoint that reachable at “/api/breadcrumbs?slug=pageslug” to asynchronously fetch the breadcumb CMS items for the current page (by slug). This hardly ever changes, so it seems logical to implement some server side caching for this endpoint by following the Netlify documentation about caching.
However, even though when the endpoint does include the right headers (if I’m understanding the documentation correctly), it still seems to run alle the code in my api handler all the time. I’ve confirmed this by adding logging right before the point the request to my CMS is actually being done. It comes by almost (not always it seems…) every time I visit the same page (so with the same slug).
My response headers are:
Age: 40
Cache-Control: public,max-age=604800
Cdn-Cache-Control: public, max-age=604800
Cf-Cache-Status: DYNAMIC
Cf-Ray: 81fb5517cbe00e33-AMS
Content-Encoding: br
Content-Type: application/json; charset=utf-8
Date: Thu, 02 Nov 2023 09:25:49 GMT
Etag: W/"3xpw3uuuj63m-df"
Nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Netlify-Vary: query=locale|slug
Server: cloudflare
Strict-Transport-Security: max-age=15552000
Vary: Accept-Encoding
X-Middleware-Next: 1
X-Nf-Render-Mode: ssr
X-Nf-Request-Id: 01HE7NMTQKCXXQY0MQB3KYV3FG
I actually also add the header Netlify-Cdn-Cache-Control: public, max-age=604800
to the response headers, but as described in the docs, this is stripped before actually sending the response to the browser.
I can imagine that it has to becached on the different CDN’s so there could be some duplicate requests at first, but the number of requests to the CMS does not seem to decrease over time.
The page I’m checking is: Tickets | I amsterdam. If you inspect the network you should see an XHR request to https://www.iamsterdam.com/api/breadcrumbs/nl?slug=/tickets
Why is the caching not working?