惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
D
Docker
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - 司徒正美
博客园 - Franky
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
AI
AI
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Secure Thoughts
博客园 - 聂微东
L
LINUX DO - 最新话题
U
Unit 42
SecWiki News
SecWiki News
A
Arctic Wolf
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Visual Studio Blog
量子位
The Cloudflare Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
Last Week in AI
Last Week in AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
Latest news
Latest news

Flavio Copes

Workers Cache: a cache in front of your Cloudflare Worker Cloudflare Drop: drag a folder, get a live site Temporary Cloudflare accounts: agents can now deploy without signing up Moondream 3.1 on Workers AI: fast vision at the edge inferencecost.dev: what will AI inference cost you at 10k users? Sitebase: all the features your website needs, in one place StackPlan: figure out where to deploy your app, and what it How the Cloudflare Pages build cache works The Summer of Code How I generate an Open Graph image for every post New: 90 free tools for developers How I added search to my static site with Pagefind How to rebuild a Cloudflare site on a schedule Cloudflare Email Workers: run code when an email arrives Cloudflare Turnstile: stop bots without annoying CAPTCHAs Cloudflare Workers: secrets and environments Cloudflare Workers observability: logs and traces Cloudflare Analytics Engine: store and query metrics The AI Workshop (July 2026 cohort) Cloudflare Cron Triggers: run a Worker on a schedule Cloudflare Durable Objects: state that lives in one place Cloudflare Queues: run work in the background Cloudflare R2: object storage without egress fees Cloudflare D1: a SQL database for your Workers Serving a website with Cloudflare Workers static assets Wrangler: the Cloudflare Workers command line tool Executor: one gateway to connect your AI agent to every tool Cloudflare Workers: your first serverless function Vercel eve: an open framework for building AI agents Flue: the open framework for building AI agents Val Town: write and deploy code in seconds A hands-on guide to The Agency, a collection of AI agents The AI Workshop (June 2026 cohort) The AI Workshop (May 2026 cohort) The AI Workshop (Apr 2026 cohort)
Cloudflare KV: a key-value store for your Workers
Flavio Copes · 2026-06-24 · via Flavio Copes

By Flavio Copes

Learn how to use Cloudflare Workers KV, an edge key-value store, to create a namespace and put and get data, ideal for sessions, feature flags and caching.

~~~

Sometimes you don’t need a full database. You just need to save a value under a key and read it back, fast.

That’s Workers KV. Think of it as a giant dictionary that lives on Cloudflare’s edge. You store a value under a key, and you can read it from anywhere in the world, very quickly.

I use it for sessions, feature flags, and caching things that are expensive to compute. Let’s see how it works.

If you’re not sure whether KV is the right fit versus D1, R2 or Durable Objects, I built a free Cloudflare storage chooser that points you to the right one.

Create a namespace

In KV, your keys live in a namespace. Create one:

npx wrangler kv namespace create SESSIONS

It prints an id. Add it to wrangler.jsonc:

{
  "kv_namespaces": [
    {
      "binding": "SESSIONS",
      "id": "the-id-it-printed"
    }
  ]
}

Now env.SESSIONS is available in your Worker.

Write and read

Writing is put, reading is get:

await env.SESSIONS.put('user-123', 'logged-in')

const status = await env.SESSIONS.get('user-123')

get returns the value, or null if the key isn’t there.

Storing objects

Values are strings, but KV can handle JSON for you. Pass an object and tell get to parse it back:

await env.SESSIONS.put('user-123', JSON.stringify({ name: 'Flavio', plan: 'pro' }))

const user = await env.SESSIONS.get('user-123', 'json')

With 'json', get returns the parsed object directly. No manual JSON.parse.

Expiring keys

This is one of my favorite features. You can tell a key to delete itself after some time. Great for sessions and caches.

Expire after one hour:

await env.SESSIONS.put('user-123', 'logged-in', { expirationTtl: 3600 })

expirationTtl is in seconds. After it passes, the key is gone. No cleanup job to write.

Delete a key

await env.SESSIONS.delete('user-123')

List keys

You can list keys, optionally by prefix:

const list = await env.SESSIONS.list({ prefix: 'user-' })
list.keys.forEach((k) => console.log(k.name))

This is handy for grouping related keys, like user-123, user-456.

The one thing to know

KV is built for reads. Reading is extremely fast, everywhere. Writing is fast too, but a change can take a few seconds to be visible in every region.

So KV is perfect when you read a lot and write occasionally: sessions, config, cached pages, flags.

It’s not the tool for data that changes constantly and must be exact the instant after you write it, like a bank balance. For that, reach for D1 or a Durable Object.

But for “save this and read it back fast,” KV is the simplest thing on the platform. The full reference is in the KV docs.

~~~

Related posts about cloudflare: