For SQL databases and structured queries, see the data operation.
Configuration
KV (Key-Value Store)
Global key-value cache with eventual consistency. Perfect for configuration, sessions, and caching.GET Operation
PUT Operation
expirationTtl(number) - Seconds until expirationexpiration(number) - Unix timestamp for expirationmetadata(object) - Custom metadata (max 1KB)
DELETE Operation
LIST Operation
prefix(string) - Filter keys by prefixlimit(number) - Max results (default: 1000, max: 1000)cursor(string) - Pagination cursor
R2 (Object Storage)
S3-compatible object storage for files, images, backups, and large data.GET Object
PUT Object
httpMetadata(object) - Standard HTTP metadatacustomMetadata(object) - Custom key-value metadata (max 2KB)
DELETE Object
LIST Objects
prefix(string) - Filter by prefixlimit(number) - Max results (default: 1000)delimiter(string) - Directory delimitercursor(string) - Pagination cursorinclude(string[]) - Include metadata:['httpMetadata', 'customMetadata']
HEAD Object (Metadata Only)
Cache API
Edge cache for ultra-fast data access across Cloudflare’s global network.GET Operation
PUT Operation
ttl(number) - Seconds until expirationcacheControl(string) - Custom Cache-Control header
DELETE Operation
Choosing Between Storage Types
| Type | Use Case | Durability | Speed | Global |
|---|---|---|---|---|
| KV | Config, sessions, cache | High (replicated) | Fast (<1ms local) | ✅ Yes |
| R2 | Files, images, backups | Very High (S3-compatible) | Medium (10-50ms) | ✅ Yes |
| Cache | Temporary data, API responses | None (can evict) | Very Fast (<1ms) | ✅ Yes |
When to Use storage vs data
Use storage when you need:- ✅ Simple key-value lookups
- ✅ Object/file storage
- ✅ Temporary caching
- ✅ Global edge caching
- ❌ SQL queries
- ❌ Relational data
- ❌ Transactions
- ❌ Complex queries with JOINs
Examples
Session Management with KV and Cookies
Combine KV storage with the cookies operation for complete session management:File Upload to R2
API Response Caching
Bindings Setup
Configure storage bindings inwrangler.toml:
Performance Tips
KV Best Practices
- Keep values under 25MB (max limit)
- Use expiration to auto-cleanup
- Leverage eventual consistency model
- Cache frequently accessed keys
R2 Best Practices
- Use multipart upload for files >100MB
- Set appropriate content types
- Use prefixes for organization
- Leverage custom metadata for search
Cache Best Practices
- Set reasonable TTLs
- Invalidate on writes
- Use cache keys carefully
- Monitor cache hit rates
Storage Limits
| Storage | Max Value Size | Max Keys | Operations |
|---|---|---|---|
| KV | 25 MB | Unlimited | 1000 write/sec |
| R2 | 5 TB per object | Unlimited | Unlimited |
| Cache | Varies by plan | N/A | Unlimited |

