Cloudflare refusing to cache responses
kylekz
PROOP

a month ago

Almost done with a migration from Vercel but I'm struggling to get cache-control headers working for caching API endpoints.

On Vercel, I have a two tiered cache:
Cache-Control: 30s -> cache in the browser for 30 seconds
CDN-Cache-Control: $value -> cache in the CDN for $value seconds
at some point I had this as a three tier cache with Cloudflare in front, which worked fine

Now, I have a Tanstack Start app deployed as a node server and it's listening on 8080 (which seems to be the Vite default?). I've pointed my custom domain to it and selected port 8080. This all works great. Problem is that my cached API endpoints are refusing to be cached by Cloudflare, always returning cf-cache-status DYNAMIC despite the cache control headers being returned:

return Response.json(somePayload, {
  headers: {
    "Cache-Control": "public, max-age=30",
    "CDN-Cache-Control": `public, max-age=2592000, stale-while-revalidate=30`
  }
});

the response headers in the browser does return these:

cache-control public, max-age=30
cdn-cache-control public, max-age=2592000, stale-while-revalidate=30
cf-cache-status DYNAMIC
content-type application/json
x-railway-edge railway/asia-southeast1-eqsg3a
x-railway-request-id yeQv3vmSTSGRSJK0AQeqjw

I'm just stumped as to why Cloudflare has determined this endpoint as uncachable. Does the Railway edge network interfere with anything here?

0 Replies

Loading...