Skip to content
worker.ts
import { drizzle } from 'drizzle-orm/d1'
import { cloudflareKVCache } from 'drizzle-cloudflare-kv-cache-adapter'

const db = drizzle(env.DB, {
  cache: cloudflareKVCache(env.CACHE),
})

// cached, edge-local, auto-invalidated
const users = await db.select().from(usersTable).$withCache()

Drizzle Cloudflare KV Cache

Cloudflare KV query caching for Drizzle ORM. Cache read-heavy queries on Workers & D1 — no Redis, no Upstash, no extra infra.

Zero extra infra

Reuse the KV namespace you already bind in your Worker. No Redis instance, no connection pool, no cold-start tax.

Drop-in adapter

Implements Drizzle’s native cache interface. Pass it to drizzle({ cache }) and use .$withCache() exactly as documented.

Automatic invalidation

Writes through Drizzle invalidate every cached query that touches the mutated tables — via a per-table reverse index in KV.

Edge-native

Built for Cloudflare Workers and D1. Tiny, tree-shakeable, ESM-only, fully typed.

Independent, community-maintained project — not affiliated with or endorsed by Drizzle ORM or Cloudflare, Inc. All trademarks belong to their respective owners. See the Introduction for details.