---
title: Cache Drivers
description: Multiple cache backends with a unified driver interface
---

## Available Drivers

| Driver | Best For | Persistence | Distributed |
|--------|----------|-------------|-------------|
| [MemoryCache](/docs/extensions/cache/drivers/memory) | Development, single-instance | No | No |
| [CloudflareKVCache](/docs/extensions/cache/drivers/cloudflare-kv) | Cloudflare Workers | Yes | Yes |

## Choosing a Driver

### Development / Testing

Use `MemoryCache` for local development. It requires no external dependencies and provides instant cache operations.

```typescript
import { MemoryCache } from "viborm/cache/memory";
import { cache } from "viborm/cache";

const client = createClient({ schema, driver }).$extends(
  cache({ driver: new MemoryCache() })
);
```

### Production - Cloudflare Workers

Use `CloudflareKVCache` when deploying to Cloudflare Workers. It provides distributed caching across Cloudflare's edge network.

```typescript
import { CloudflareKVCache } from "viborm/cache/cloudflare-kv";
import { cache } from "viborm/cache";

const client = createClient({ schema, driver }).$extends(
  cache({ driver: new CloudflareKVCache(env.MY_KV_NAMESPACE) })
);
```

### Production - Other Environments

For other production environments (Node.js, Vercel, AWS Lambda), implement a custom driver using Redis, Upstash, or another distributed cache. See [Custom Drivers](/docs/extensions/cache/drivers/custom).

## Driver Interface

All cache drivers extend the abstract `CacheDriver` class and implement four methods: `get`, `set`, `delete`, and `clear`. See [Custom Drivers](/docs/extensions/cache/drivers/custom) for the full interface and reference implementations.
