Skip to content
66 changes: 66 additions & 0 deletions src/content/docs/kv/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
LinkTitleCard,
Plan,
RelatedProduct,
Tabs,
TabItem
} from "~/components";

<Description>
Expand All @@ -22,8 +24,72 @@ Create a global, low-latency, key-value data storage.

<Plan type="workers-all" />

## What is Workers KV?

Workers KV is a data storage that allows you to store and retrieve data globally. With Workers KV, you can build dynamic and performant APIs and websites that support high read volumes with low latency.

Workers KV is ideal for projects that require:

- High volumes of reads and/or repeated reads to the same keys.
- Per-object time-to-live (TTL).
- Distributed configuration.

For example, you can use Workers KV for:

- Caching API responses.
- Storing user configurations / preferences.
- Storing user authentication details.

<Tabs>
<TabItem label="index.ts">
```ts
export interface Env {
YOUR_BINDING: KVNamespace;
}

export default {
async fetch(request, env, ctx): Promise<Response> {
await env.YOUR_BINDING.put('KEY', 'VALUE');
const value = await env.YOUR_BINDING.get('KEY');
const allKeys = await env.YOUR_BINDING.list();
await env.YOUR_BINDING.delete('KEY');
return new Response(
JSON.stringify({
value: value,
allKeys: allKeys,
}),
{
headers: {
'Content-Type': 'application/json'
},
}
);
},
};

```
</TabItem>
<TabItem label="wrangler.json">
```json
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "WORKER-NAME",
"main": "src/index.ts",
"compatibility_date": "2025-02-04",
"observability": {
"enabled": true
},

"kv_namespaces": [
{
"binding": "YOUR_BINDING",
"id": "<YOUR_BINDING_ID>"
}
]
```
</TabItem>
</Tabs>

---

## Features
Expand Down
Loading