[wrangler] Support volatile cache bindings in local dev - #14868
[wrangler] Support volatile cache bindings in local dev#14868irvinebroque wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: bd9b599 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
✅ All changesets look good |
|
I've now thoroughly reviewed the change. Let me summarize my findings: Correctness verification:
Let me check one last potential real issue: the miniflare zod schema requires The workerd sample shows limits are part of the config. Since these are required in both the wrangler Let me double-check the I've completed a thorough review. The implementation is correct: the data flow, type design, and the important LGTM |
@cloudflare/autoconfig
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Important
This draft PR is not intended to be merged. It exists so CI can produce a PR prerelease of Wrangler that can configure MemoryCache in local workerd development.
Why this exists
workerd already has an experimental in-memory
MemoryCachebinding. Wrangler can carry the internalvolatile_cachebinding shape, but local development did not translate that configuration into workerd'smemoryCachebinding.In plain language: the configuration described the cache, but
wrangler devdid not connect that description to the local runtime. This PR adds the missing local-runtime connection through Wrangler and Miniflare. Production deployment behavior is unchanged.Before and after
Before this change, an
unsafe.bindingsentry withtype: "volatile_cache"was not available as a working MemoryCache binding in local development.After this change, Wrangler passes the cache ID and limits to Miniflare, and Miniflare writes the corresponding
memoryCachebinding into workerd's configuration.How to use the PR prerelease
Add the binding to
wrangler.jsonc:{ "unsafe": { "bindings": [ { "name": "AIG_VOLATILE_CACHE", "type": "volatile_cache", "cache_id": "ai-gateway-worker-staging", "max_keys": 10000, "max_value_size": 16384, "max_total_value_size": 33554432 } ] } }The binding is then available on the Worker environment in local development:
read()returns an unexpired cached value when one exists. On a cache miss, it runs the callback; eligible values can then be retained subject to expiration and the configured limits.The cache belongs to the local workerd process. It is not durable storage and should not be treated like KV, D1, or another persistent product.
Authoritative references:
Scope
wrangler devand Miniflare only.cache_id,max_keys,max_value_size, andmax_total_value_sizeto workerd's MemoryCache configuration.unsafe.bindingsconfiguration surface.