Skip to main content
Blaze injects every KV namespace declared in your wrangler.toml directly onto req.env with full type safety. Once you add the binding to your Env type and pass it to createApp<Env>(), every handler in your application can read, write, list, and delete keys — no extra setup, no manual passing of the namespace, no casting.

Configure the binding

Start by declaring the namespace in wrangler.toml, then mirror it in your Env type.
1

Add the namespace to wrangler.toml

wrangler.toml
2

Define the Env type

src/types/env.ts
3

Pass Env to createApp

src/index.ts

Reading from KV

Use req.env.CACHE.get(key, { type: 'json' }) to retrieve a stored value and let Blaze handle deserialization. The method returns null when the key does not exist, so always guard against a missing value before responding.
The type: 'json' option tells the KV runtime to deserialize the stored string automatically. Other supported types are 'text' (default), 'arrayBuffer', and 'stream'.

Writing to KV

Use req.env.CACHE.put(key, value, options) to store a value. Pass expirationTtl (seconds from now) or expiration (Unix timestamp) to set a TTL — keys without a TTL persist indefinitely.
KV put operations are strongly consistent within the same Cloudflare datacenter but eventually consistent globally. Expect propagation delays of up to 60 seconds across regions.

Listing keys

req.env.CACHE.list() returns up to 1,000 keys at a time. Use the prefix option to scope the listing, and check list_complete to detect when there are more pages to fetch.

Deleting keys

req.env.CACHE.delete(key) removes a key immediately. Deleting a key that does not exist is a no-op — no error is thrown.

Fire-and-forget writes

When a KV write does not need to complete before you send a response, hand the promise to req.ctx.waitUntil(). Blaze will keep the Worker alive to finish the write without blocking the response returned to the client.
KV is an excellent store for configuration values and feature flags that change infrequently. Because Cloudflare isolates can persist across multiple requests within the same datacenter, you can read a flag once per isolate startup and cache it in a module-level variable — dramatically reducing KV read costs for high-traffic workers.