Lộ trình đang học Current learning path

Developer Platform Developer Platform

Build và deploy apps trên Cloudflare. Build and deploy apps on Cloudflare.

Về trang lộ trình Track home

Phần 3: Chọn storage đúng Part 3: Pick the right storage · Bài 1/3 Lesson 1/3

KV cho config và cache nhẹ KV for config and light cache

Lưu feature flags, session token ngắn, rate limit counter. Không dùng KV cho giao dịch tài chính cần consistency cao. Store feature flags, short session tokens, rate limit counters. Avoid KV for financial transactions needing strong consistency.

Các bước thực hiện Step-by-step

  1. Tạo KV namespace: `wrangler kv namespace create APP_CONFIG`. Create KV namespace: `wrangler kv namespace create APP_CONFIG`.
  2. Binding trong wrangler.toml / Pages settings. Bind in wrangler.toml / Pages settings.
  3. Đọc/ghi từ Worker: `env.KV.put(key, value)`. Read/write from Worker: `env.KV.put(key, value)`.
  4. Dùng cho flags, cache config — không cho ledger tài chính. Use for flags, config cache — not financial ledgers.

Giải thích chi tiết Detailed explanation

KV eventually consistent, đọc cực nhanh tại edge — ideal cho read-heavy config. KV is eventually consistent with extremely fast edge reads — ideal for read-heavy config.

Lưu ý (best practices) Note (best practices)

Dùng binding (KV, R2, D1…) trực tiếp trong Worker — không gọi REST API Cloudflare từ trong Worker (thêm latency, auth và phức tạp không cần thiết). Use bindings (KV, R2, D1, etc.) directly in Workers — do not call the Cloudflare REST API from within a Worker (adds latency, auth, and unnecessary complexity).

Nguồn: Source: Workers Best Practices Workers Best Practices

Ví dụ triển khai (Cloudflare Resources) Deployment examples (Cloudflare Resources)

Ví dụ chính thức từ Cloudflare Resources — gợi ý theo chủ đề bài học trong lộ trình này. Official examples from Cloudflare Resources — matched to this lesson within this path.

Xem thêm ví dụ trong lộ trình → More examples in this path →

Tài liệu Cloudflare Developers Cloudflare Developer docs

Cloudflare API (tham khảo) Cloudflare API (reference)

Dùng khi tự động hóa bước này qua script hoặc Terraform — cần API token phù hợp. Use when automating this step via script or Terraform — requires an appropriate API token.

developers.cloudflare.com/api ↗

Sản phẩm liên quan Related products

Học xong hoặc muốn đổi hướng? Finished or want a different path?

Ba lộ trình độc lập — mỗi lộ trình chỉ gồm bài học và tài liệu trong phạm vi đó. Chọn lộ trình khác khi sẵn sàng, không cần học song song. Three independent paths — each includes only lessons and materials for that scope. Switch when you are ready; no need to study paths in parallel.

Chưa chắc — làm bài chọn lộ trình Not sure — use the path selector · So sánh cả ba lộ trình Compare all three paths