Isaac
Isaac
CDCloudflare Developers
Created by Isaac on 11/28/2023 in #workers-help
cache miss due to fetch redirect?
Hi! I am trying to create a worker to proxy a custom origin. The origin first responds with a 307 redirect, which changes dynamically. When the redirect is followed, the origin delivers the document.
The problem is that I cannot get cloudfare fetch to cache; and I'm not sure how to debug it or what else to try... Maybe it's because of the redirect? Or maybe because of the cache-control headers coming from the origin? I'm stumped. When I hit my worker repeatedly, I get the following headers (the worker sends back cf-ray and cf-cache-status from its origin fetch)
< HTTP/2 200
< date: Tue, 28 Nov 2023 17:43:35 GMT
< content-type: text/csv
< cf-ray: 82d469fb781c429e-EWR
< cf-cache-status: MISS
< access-control-allow-origin: *
< cache-control: public, max-age=600
...
< HTTP/2 200
< date: Tue, 28 Nov 2023 17:43:35 GMT
< content-type: text/csv
< cf-ray: 82d469fb781c429e-EWR
< cf-cache-status: MISS
< access-control-allow-origin: *
< cache-control: public, max-age=600
...
Here's what the origin returns when curled directly:
< HTTP/2 307
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< location: ...
< HTTP/2 307
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< location: ...
< HTTP/2 200
< content-type: text/csv
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< HTTP/2 200
< content-type: text/csv
< cache-control: no-cache, no-store, max-age=0, must-revalidate
...
const res = await fetch(
`https://docs.google.com/spreadsheets/d/${env.GSHEET_ID}/export?format=csv&gid=${env.GSHEET_GID}`,
{
cf: { cacheTtl: 600 }, // also tried cacheEverything -- didn't help and docs say it's redundant.
}
);
return new Response(...)
...
...
const res = await fetch(
`https://docs.google.com/spreadsheets/d/${env.GSHEET_ID}/export?format=csv&gid=${env.GSHEET_GID}`,
{
cf: { cacheTtl: 600 }, // also tried cacheEverything -- didn't help and docs say it's redundant.
}
);
return new Response(...)
...
2 replies