Cloudflare Workers edge cache hits still count as billable Worker invocations
0 reputation · 07 Apr 2022, 21:51 UTC
0 reputation · 07 Apr 2022, 21:51 UTC
A low-traffic application on Cloudflare Workers needs to confirm whether edge-cached responses reduce billable Worker executions. The goal is to determine if a request that matches a Workers route but is served from cache still consumes the free-tier invocation allowance.
Cloudflare bills Workers by request count and compute time, and published free-tier limits can change. It is uncertain whether Cache API responses inside a Worker count as invocations, whether edge cache hits bypass a matched Worker route, and whether subrequests carry separate charges. Durable Objects are excluded from this review.
Does a Cache API hit inside a Worker count toward the daily free-tier request limit? Does an edge cache hit bypass the Worker when the URL matches a Workers route? Are subrequests billed separately from Worker invocations on the free tier?
35275 reputation · 08 Apr 2022, 00:02 UTC
Yes, if a request matches a defined Workers route, it counts as a billable Worker invocation, even if the response is served from the edge cache. The Worker must execute to determine that the cache entry exists and to return it, which consumes the free-tier request allowance.
There is a distinction between Cloudflare's static asset caching and the Workers Cache API:
On the free tier, subrequests made from a Worker (e.g., via `fetch()`) do not count as separate Worker invocations. They are bundled within the primary Worker's execution time. However, if the subrequest matches another Workers route, that second Worker will execute and count as its own invocation.
| Scenario | Billed Invocation? |
|---|---|
| Route match + Cache API hit | Yes |
| No route match + Edge Cache | No |
| Subrequest to external API | No |
| Subrequest to another Worker route | Yes (for the target Worker) |
To verify your specific usage consumption, you can monitor the Cloudflare dashboard usage tab or use the following header in your response to inspect execution details:
CF-Workers-Cache: HIT
Note: If you see CF-Workers-Cache: HIT, the Worker ran, and the invocation was counted against your daily limit.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 08 Apr 2022, 06:56 UTC
Each Worker invocation has a hard limit of 50 subrequests (including caches.default.match() calls). Exceeding it throws an exception even though subrequests don’t add billable invocations. Separately, a Cache Rule or Page Rule set to Cache Everything and Disable Workers for a hostname will serve the edge cache without invoking the Worker — but this is an explicit opt-in, not default behavior.
In the Workers analytics “Requests” graph, every route match increments the counter, including Cache API hits. A minimal test Worker that logs console.log('invoked') and returns caches.default.match(request) will show the request count rise on each hit, confirming the billing model.