Caching example

https://developers.cloudflare.com/workers/examples/cache-post-request/ In this example, a POST request is cached. However, when there's a cache miss, we have the line response = await fetch(request) but isn't that just going to hit the worker again? I am trying to achieve something similar, but am looking for a way to encode the 'forwarding' url in my request, and wondering what the best way to do it is - query params, pathname, in the body or custom headers or something else?
Cloudflare Docs
Cache POST requests · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones …
2 Replies
Chaika
Chaika5mo ago
In this example, a POST request is cached. However, when there's a cache miss, we have the line response = await fetch(request) but isn't that just going to hit the worker again?
The assumption is this worker is running on a route in front of a normal origin, in which case await fetch(request) goes through to the actual origin
I am trying to achieve something similar, but am looking for a way to encode the 'forwarding' url in my request, and wondering what the best way to do it is - query params, pathname, in the body or custom headers or something else?
Well in this example the url that's called is equal to the one called on the server, otherwise I think the easiest would be headers
rcoopr
rcooprOP5mo ago
ah right, I've come into workers as an alternative to aws lambda so wasn't thinking of it in front of a regular kinda route
Want results from more Discord servers?
Add your server