Overview
Data members handle storage operations across Cloudflare’s data primitives: KV (key-value), D1 (SQL), R2 (object storage), and Vectorize (vector database). They abstract away platform-specific APIs with a unified interface.Storage Types
KV
Global key-value cache with eventual consistency
D1
Serverless SQLite database for relational data
R2
Object storage compatible with S3 API
Vectorize
Vector database for embeddings and semantic search
Basic Configuration
KV Storage
GET Operation
PUT Operation
DELETE Operation
LIST Operation
D1 Database
Query Operation
Parameterized Queries
INSERT/UPDATE/DELETE
R2 Object Storage
GET Object
PUT Object
DELETE Object
LIST Objects
Vectorize
Insert Vectors
Search Vectors
Custom Data Members
For complex operations, implement custom logic:Bindings Setup
Configure bindings inwrangler.toml:
Common Patterns
Cache-Aside Pattern
Write-Through Cache
Pagination
Error Handling
Performance Tips
Use Batch Operations
Index Frequently Queried Fields
Use KV for Hot Data
Testing Data Members
Best Practices
- Use appropriate storage - KV for cache, D1 for relational, R2 for files, Vectorize for vectors
- Set TTL on cached data - Prevent stale data with appropriate expiration
- Parameterize queries - Use
?placeholders to prevent SQL injection - Index database fields - Speed up queries with proper indexes
- Batch operations - Combine multiple operations when possible
- Handle not found - Check
foundboolean in output - Use transactions - For related updates in D1
- Monitor storage limits - KV: 25MB per value, D1: 500MB per database

