Cooleg
Cooleg
CDCloudflare Developers
Created by Cooleg on 4/29/2023 in #workers-help
Cache seems to not be storing anything
In my calls TTL is set to 1800 and checking with postman the cache control is being set in my response, so the header is set just fine. I just can't wrap my head around why the console.log is logging undefined for this code that feels like it should be caching properly, but somehow literally just after caching it, its undefined. Any help? Other info: Basically, trying to make a sort of proxy for a online API, but that API has cache headers set to private and 0 cache time, which wasn't allowing the response to be cached. I am creating the new response with all the headers and the body copied but just the Cache-Control modified as I assumed this would work, like the article I linked talks about at the bottom, but the cache is telling me nothing is stored.
head.set('Cache-Control', 'public, max-age='+ttl+', s-maxage='+ttl);
let result = new Response(resp.body, {status: 200, headers: head})
await caches.default.put(req, result.clone());
console.log(await caches.default.match(req));
head.set('Cache-Control', 'public, max-age='+ttl+', s-maxage='+ttl);
let result = new Response(resp.body, {status: 200, headers: head})
await caches.default.put(req, result.clone());
console.log(await caches.default.match(req));
https://developers.cloudflare.com/workers/learning/how-the-cache-works/
36 replies