All docs / Store data
Key-value store
Fast reads of small values by key, for settings, sessions, flags and caches.
Open in the consoleA key-value namespace stores values (text, JSON or bytes) under string keys. Reads are served from the edge node's local copy, so they are very fast; a write takes a moment to reach every node.
Create and bind
Create a namespace under Key-value, then bind it to an app, or declare it in the config and let rr deploy create it:
jsonc
"kv_namespaces": [{ "binding": "CACHE", "title": "my-cache" }]Use it from code
js
await env.CACHE.put("user:42", JSON.stringify(user), { expirationTtl: 3600 });
const user = await env.CACHE.get("user:42", "json");
const { keys, cursor } = await env.CACHE.list({ prefix: "user:" });
await env.CACHE.delete("user:42");Good to know
- Changes can take a short time to appear everywhere. For data that must be read back immediately and exactly, use the or a Durable Object.