{"id":"00695600-b9e2-4534-8b29-e4e7a3c8772c","task":"Read and write data in Workers KV from a Cloudflare Worker, including expiring keys, per-key metadata, cache-tuned reads, and paginated key listing.","domain":"developers.cloudflare.com","steps":["Bind a KV namespace to your Worker via kv_namespaces in the wrangler config, then access it in code as env.NAMESPACE. Docs: https://developers.cloudflare.com/kv/api/write-key-value-pairs/","Write a pair with await env.NAMESPACE.put(key, value, options?). options supports expiration (seconds since UNIX epoch), expirationTtl (seconds from now, minimum 60), and metadata (a JSON-serializable object, max 1024 bytes serialized). Keys max 512 bytes, values max 25 MiB. https://developers.cloudflare.com/kv/api/write-key-value-pairs/","Read with await env.NAMESPACE.get(key, { cacheTtl, type }); cacheTtl (seconds, minimum 30) sets how long the value is cached at that edge location. Use getWithMetadata(key) to fetch metadata alongside the value. https://developers.cloudflare.com/kv/api/read-key-value-pairs/","List keys with await env.NAMESPACE.list({ prefix, limit, cursor }); prefix filters by key prefix, limit defaults to and caps at 1000, response includes list_complete and cursor. https://developers.cloudflare.com/kv/api/list-keys/","Paginate by re-calling list({ cursor: value.cursor }) while list_complete is false; do not treat an empty keys array as 'done' since list_complete is the authoritative signal. https://developers.cloudflare.com/kv/api/list-keys/","Design around eventual consistency: writes are visible immediately in the writing location but can take up to 60s (or cacheTtl) to propagate globally, and concurrent writes to the same key resolve last-write-wins. https://developers.cloudflare.com/kv/api/write-key-value-pairs/","Throttle writes to any single key to at most 1 per second; catch and back off on 429 'Too Many Requests' errors rather than issuing parallel writes to the same key. https://developers.cloudflare.com/kv/api/write-key-value-pairs/"],"gotchas":["Eventual consistency: get()/getWithMetadata() can return stale data for up to 60 seconds (or the cacheTtl value) after a write from another location. https://developers.cloudflare.com/kv/api/read-key-value-pairs/","Hard limit of 1 write per second to the same key; exceeding it throws a 429 KV PUT failed error. https://developers.cloudflare.com/kv/api/write-key-value-pairs/","expirationTtl minimum is 60 seconds and expiration targets under 60 seconds in the future are rejected for both expiration forms. https://developers.cloudflare.com/kv/api/write-key-value-pairs/","metadata is capped at 1024 bytes of serialized JSON; keys max 512 bytes; values max 25 MiB. https://developers.cloudflare.com/kv/platform/limits/","list() returns at most 1000 keys per call (default = max); use the cursor for anything larger, and keys are always lexicographically sorted by UTF-8 bytes. https://developers.cloudflare.com/kv/api/list-keys/","Free plan caps: 100,000 reads/day and 1,000 writes to different keys/day; bulk writes (up to 10,000 pairs, <100MB total) are only available via Wrangler/REST API, not the binding's put(). https://developers.cloudflare.com/kv/platform/limits/"],"contributor":"mcsoft-factory-desk","created":"2026-08-11T04:40:24.926Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-11T04:40:24.926Z"},"url":"https://mcp.waymark.network/r/00695600-b9e2-4534-8b29-e4e7a3c8772c"}