7/6/2026 at 2:29:52 PM
> This is the caching API we've always wanted Workers to have. Here's why it took us this longI was looking forward to the "why it took us this long" explanation but it wasn't explicitly spelled out. Any Cloudflare staff here able to expand on that?
(The article does a good job of showing how many different smart design decisions went into this, but given caching is core to what a Cloudflare does I'm still a little surprised it took 9 years to get here!)
by simonw
7/6/2026 at 3:48:35 PM
The honest answer is:We implemented the "standard" Cache API back in the early days because it was a standard, one which was intended to be used together with the Service Workers API, which we were also building around back then.
But it was never a good fit. The get/put API was designed for a local browser cache, not a distributed cache like Cloudflare's. We probably should have realized this before implementing it, but it really became obvious over the years of actual use.
But given we had something that mostly worked for most use cases, it was hard to prioritize redoing it against all the other things on our plate. So we deferred.
More recently, architectural changes we've been making in Workers for other reasons happened to make it significantly easier to finally implement this the way we wanted, and we were able to find some engineering time to get it over the line.
Gory details for the curious: We've been improving the infrastructure around the notion of workers having multiple "entrypoints", with the ability to parameterize those entrypoints. ctx.props[0] and ctx.exports[1] are part of this. A lot of this was motivated by Dynamic Workers sandboxing, but the concept also presents a clean way to inject a cache between two parts of the same worker, by applying it to the entrypoint and having the worker call itself using ctx.exports.
Moreover, the introduction of "channel tokens" made a big difference[2][3]. Essentially I created a way to encode a token (bytes) representing an arbitrary entrypoint to a Worker, complete with its serialized parameters. I did this to enable these entrypoint stubs to be passed over RPC, which is again useful for sandboxing use cases, but it also created a convenient, encapsulated way to pass information through our cache infrastructure about what worker should run at the other end.
It's not a huge breakthrough or anything, but I think it made the architecture clearer in everyone's mind to the point that we got excited about using it to implement caching properly, finally.
[0] https://developers.cloudflare.com/workers/runtime-apis/conte...
[1] https://developers.cloudflare.com/workers/runtime-apis/conte...
[2] https://github.com/cloudflare/workerd/blob/main/src/workerd/...
[3] https://github.com/cloudflare/workerd/blob/main/src/workerd/...
by kentonv
7/6/2026 at 4:05:19 PM
Realizing there's a more fundamental piece I'm not explaining well here.Our architecture is something like:
ingress -> routing -> security -> workers -> cache -> origin
That is, workers run "in front of" cache. That's usually what you want. Workers run on the edge, so putting them in front of cache doesn't cost anything in terms of latency, and there's a lot of useful stuff you can do only if they run in front, e.g. serving pages from cache but customizing them for specific users.
Putting workers behind cache is an architectural change. All of the logic around routing to them lives in front of the cache. And it makes Workers a lot less useful.
We weren't that excited about it until we had a clearer story for how to run custom logic on both sides of the cache, but it was pretty unclear how to do that in a nice way until the recent developments around ctx.props, ctx.exports, channel tokens, etc.
by kentonv
7/6/2026 at 4:22:53 PM
Does that new architecture make it more expensive to serve worker’s static assets and do worker-to-worker invocations? Or just harder to measure?This change in billing makes enabling caching not such a straightforward decision, and encourages separating cached and non-cached parts of your workers into two separate workers, which is a bit annoying.
by drdexebtjl
7/6/2026 at 4:59:50 PM
I wasn't personally involved in pricing here so I can't really say exactly why it is the way it is.However, I'd note that, in terms of our costs, it's often cheaper for us to run your Worker than to serve from cache. Consider that Workers run locally in whatever edge location the request landed in. We are not saving any bandwidth costs by putting the cache in front of Workers rather than behind, and we've built an architecture such that running a Worker is extremely cheap, almost free.
In that light, making cache hits free would basically be giving away money. To be honest, that is another reason why implementing cache in front of Workers has been held back so long. I think the team finally decided that the only way we can deliver it without giving away too much money is to charge full price for the requests. Workers pricing is already incredibly generous, and we do need to run a business at the end of the day.
(Of course, a cache hit still saves you the CPU pricing. CPU time pricing more directly translates to costs for us, so that makes sense.)
I admit the side effect on static assets is a little weird. But no other provider offers unlimited free static asset serving to start with -- so it's only weird relative to our own unreasonable standards. :) I think the thought here is that if you need caching in front of Workers, that implies you are doing complex work in Workers and getting a lot of value out of them. So a bit of "price segmentation" kicks in here. That said, you can work around it by serving static assets from another hostname, etc.
by kentonv
7/6/2026 at 5:29:22 PM
No objection towards charging for cache hits, when the worker would have ran. That (except in worker-to-worker invocations) is always a strict upgrade, when it comes to pricing.Worker-to-worker invocations also now participate in the cache, so despite the pricing increase, at least we’re getting some added value.
But for static assets in particular, I don’t see what value the cache is adding, so it feels like pure price segmentation.
Or, to put it another way, you were already caching the static assets and not having the workers serve them. Now you're doing the same thing, but charging for it.
by drdexebtjl
7/6/2026 at 6:07:06 PM
blog post didn't cover two details re stale-while-revalidate:1. What headers does content that will revalidate use on client. Eg can a react hook trigger if a cms json revalidates?
2. If edge worker can call database worker: if database worker sends stale while revalidate, does that revalidate whole worker chain?
btw overall very cool, esp fine grained cache for authed/etc data
by tarasglek
7/6/2026 at 2:43:13 PM
The article was very clearly written or heavily edited by AI, which I suspect explains some of the peculiarities in structure and wording.by tshaddox