Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/kv/README.md
1# Cloudflare Workers KV23Globally-distributed, eventually-consistent key-value store optimized for high read volume and low latency.45## Overview67KV provides:8- Eventual consistency (60s global propagation)9- Read-optimized performance10- 25 MiB value limit per key11- Auto-replication to Cloudflare edge12- Metadata support (1024 bytes)1314**Use cases:** Config storage, user sessions, feature flags, caching, A/B testing1516## When to Use KV1718| Need | Recommendation |19|------|----------------|20| Strong consistency | → [Durable Objects](../durable-objects/) |21| SQL queries | → [D1](../d1/) |22| Object storage (files) | → [R2](../r2/) |23| High read, low write volume | → KV ✅ |24| Sub-10ms global reads | → KV ✅ |2526**Quick comparison:**2728| Feature | KV | D1 | Durable Objects |29|---------|----|----|-----------------|30| Consistency | Eventual | Strong | Strong |31| Read latency | <10ms | ~50ms | <1ms |32| Write limit | 1/s per key | Unlimited | Unlimited |33| Use case | Config, cache | Relational data | Coordination |3435## Quick Start3637```bash38wrangler kv namespace create MY_NAMESPACE39# Add binding to wrangler.jsonc40```4142```typescript43// Write44await env.MY_KV.put("key", "value", { expirationTtl: 300 });4546// Read47const value = await env.MY_KV.get("key");48const json = await env.MY_KV.get<Config>("config", "json");49```5051## Core Operations5253| Method | Purpose | Returns |54|--------|---------|---------|55| `get(key, type?)` | Single read | `string \| null` |56| `get(keys, type?)` | Bulk read (≤100) | `Map<string, T \| null>` |57| `put(key, value, options?)` | Write | `Promise<void>` |58| `delete(key)` | Delete | `Promise<void>` |59| `list(options?)` | List keys | `{ keys, list_complete, cursor? }` |60| `getWithMetadata(key)` | Get + metadata | `{ value, metadata }` |6162## Consistency Model6364- **Write visibility:** Immediate in same location, ≤60s globally65- **Read path:** Eventually consistent66- **Write rate:** 1 write/second per key (429 on exceed)6768## Reading Order6970| Task | Files to Read |71|------|---------------|72| Quick start | README → configuration.md |73| Implement feature | README → api.md → patterns.md |74| Debug issues | gotchas.md → api.md |75| Batch operations | api.md (bulk section) → patterns.md |76| Performance tuning | gotchas.md (performance) → patterns.md (caching) |7778## In This Reference7980- [configuration.md](./configuration.md) - wrangler.jsonc setup, namespace creation, TypeScript types81- [api.md](./api.md) - KV methods, bulk operations, cacheTtl, content types82- [patterns.md](./patterns.md) - Caching, sessions, rate limiting, A/B testing83- [gotchas.md](./gotchas.md) - Eventual consistency, concurrent writes, value limits8485## See Also8687- [workers](../workers/) - Worker runtime for KV access88- [d1](../d1/) - Use D1 for strong consistency needs89- [durable-objects](../durable-objects/) - Strongly consistent alternative90