Using cache put and match in the same worker

Hello, As the title says, I want to cache something and verify it's there. This works just fine in wrangler dev but not in prod. Is this possible? Am I missing something simple? Playground: http://tinyurl.com/3zax9ms7
12 Replies
geomaster
geomaster13mo ago
Not sure if related to your issue, but this is not expected to work in Playground:
However, any Cache API operations in the Cloudflare Workers dashboard editor, Playground previews, and any *.workers.dev deployments will have no impact.
(from https://developers.cloudflare.com/workers/runtime-apis/cache/)
Justin Grote
Justin GroteOP13mo ago
@geomaster oh thanks, I didn't think about that for playground, but it definitely doesn't work with a production deploy https://pwsh-gallery-preview.jwg.workers.dev/az.accounts/page/recent.json This same function works just fine when running wrangler dev locally
Chaika
Chaika13mo ago
There's no cache on workers.dev either only Custom Domains
Justin Grote
Justin GroteOP13mo ago
I'd guess because the way the cache is abstracted to the sqlite database in the local runner doesn't behave exactly as the local one Derp! I forgot about that! Thanks, I'll deploy a custom domain for that
Chaika
Chaika13mo ago
I'd question if that would work anyway though, I would have thought cache needs valid URLs i.e https://test.invalid
Justin Grote
Justin GroteOP13mo ago
@Chaika it'll throw an exception if put doesn't like the uri
Chaika
Chaika13mo ago
Might be fine. I've just never tried it without a valid url before. It'd be easy to try that as well if it doesn't work on a Custom Domain though
Justin Grote
Justin GroteOP13mo ago
In my non-dashboard prod code it is a valid URL in the same custom domain it uses the request URL as the base I basically need to do a heavy fetch in the backend and I want to pre-populate some cache URLs for fetches that will occur after that initial heavy requests @Chaika thanks for your quick eyes! Appreciated Is there a way to mark as answered in this forum?
Chaika
Chaika13mo ago
ah it worked on a Custom Domain?
Justin Grote
Justin GroteOP13mo ago
I guess the solved tag is it
Chaika
Chaika13mo ago
Yea you can just add the Solved tag
Justin Grote
Justin GroteOP13mo ago
haven't tried but I'll bet for sure that was it, I'm doing it now but I have to set up the custom domain first @Chaika that worked: https://preview.pwsh.gallery/Az.Accounts/page/recent.json
Want results from more Discord servers?
Add your server