Cloudflare KV Adapter
The Cloudflare KV adapter stores your content schema in Cloudflare Workers KV, providing globally distributed key-value storage with edge reads.
Installation
Section titled “Installation”npm install @useacms/cliConfiguration
Section titled “Configuration”import { defineConfig } from '@useacms/client';import { localFile, cloudflareKV } from '@useacms/cli/adapters';
export default defineConfig({ dev: localFile({ path: './acms.json' }), production: cloudflareKV({ accountId: process.env.CF_ACCOUNT_ID, namespaceId: process.env.CF_KV_NAMESPACE_ID, apiToken: process.env.CF_API_TOKEN, }),});Options
Section titled “Options”| Option | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
namespaceId | string | Yes | KV namespace ID |
apiToken | string | Yes | Cloudflare API token with KV read/write permissions |
1. Create a Cloudflare API Token
Section titled “1. Create a Cloudflare API Token”- Go to Cloudflare Dashboard > Profile > API Tokens.
- Create a new token with “Workers KV Storage” read and write permissions.
- Copy the token.
2. Create a KV Namespace
Section titled “2. Create a KV Namespace”Using the Cloudflare dashboard:
- Go to Workers & Pages > KV.
- Create a new namespace (e.g.,
acms-content). - Copy the namespace ID.
Or using Wrangler:
npx wrangler kv namespace create "acms-content"3. Configure Environment Variables
Section titled “3. Configure Environment Variables”CF_ACCOUNT_ID=your_account_idCF_KV_NAMESPACE_ID=your_namespace_idCF_API_TOKEN=your_api_tokenacms push # Upload to Cloudflare KVacms pull # Download from Cloudflare KVacms sync # Bi-directional syncHow It Works
Section titled “How It Works”- Read: Fetches the schema from the KV namespace using the Cloudflare API.
- Write: Writes the schema as a JSON value to the KV namespace.
KV provides eventual consistency for writes (usually propagates globally within 60 seconds) and strong consistency for reads from the same location.
Use Cases
Section titled “Use Cases”- Cloudflare-hosted apps — Native integration with Cloudflare Workers and Pages.
- Global distribution — Content available at hundreds of edge locations.
- Runtime strategy — Works well with
strategy: 'runtime'for dynamic content. - Cloudflare Pages — Ideal for sites deployed on Cloudflare Pages.
Limitations
Section titled “Limitations”- Write propagation is eventually consistent (up to 60 seconds globally).
- KV has a value size limit of 25 MB per key.
- Requires a Cloudflare account.
Next Steps
Section titled “Next Steps”- Learn about Cloudflare Pages deployment
- Explore the Convex adapter for real-time sync