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

推荐订阅源

L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
TaoSecurity Blog
TaoSecurity Blog
博客园_首页
Vercel News
Vercel News
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Exploit Database - CXSecurity.com
量子位
Project Zero
Project Zero
A
Arctic Wolf
小众软件
小众软件
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
P
Privacy & Cybersecurity Law Blog
Security Latest
Security Latest
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
Schneier on Security
Schneier on Security
The Hacker News
The Hacker News
K
Kaspersky official blog
C
Check Point Blog
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
人人都是产品经理
人人都是产品经理
AI
AI
Cisco Talos Blog
Cisco Talos Blog
MyScale Blog
MyScale Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
S
Schneier on Security
P
Palo Alto Networks Blog

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: