Caching response headers from Worker

Hi, I have a Worker that only emits headers (mostly 301/302 redirects; no body) as part its HTTP response based on the requested URL. Each incoming request hits the Worker which processes the request URL and then returns a set of headers. This is largely wasteful for my use case, because most requests will return the same response.

To avoid excessive Worker invocations, is it possible to somehow cache the response (headers) from a Worker, so that identical requests don’t trigger the Worker again, and instead pick the cached response?

I don’t think that is supported at this time, no.

Workers execute before any caching is applied (since they have pretty granular control over how the cache works through the caching API, see Cache · Cloudflare Workers docs and How the Cache works · Cloudflare Workers docs).

Thanks JB, I thought so. Too bad that caching isn’t offered for Worker response, to bypass unnecessary execution.

Edit: Seems like AWS [email protected] can cache output: Edge Computing| CDN, Global Serverless Code, Distribution | AWS [email protected]

1 Like