@@ -142,6 +142,55 @@ const federation = createFederation<void>({
142142[ `PostgresKvStore` ] : https://jsr.io/@fedify/postgres/doc/kv/~/PostgresKvStore
143143[ @fedify/postgres ] : https://github.com/fedify-dev/postgres
144144
145+ ### ` WorkersKvStore ` (Cloudflare Workers only)
146+
147+ * This API is available since Fedify 1.6.0.*
148+
149+ ` WorkersKvStore ` is a key–value store implementation for [ Cloudflare Workers]
150+ that uses Cloudflare's built-in [ Cloudflare Workers KV] API. It provides
151+ persistent storage and good performance for Cloudflare Workers environments.
152+ It's suitable for production use in Cloudflare Workers applications.
153+
154+ Best for
155+ : Production use in Cloudflare Workers environments.
156+
157+ Pros
158+ : Persistent storage, good performance, easy to set up.
159+
160+ Cons
161+ : Only available in Cloudflare Workers runtime.
162+
163+ ~~~~ typescript twoslash
164+ // @noErrors: 2345
165+ import type { FederationBuilder } from " @fedify/fedify" ;
166+ const builder = undefined as unknown as FederationBuilder <void >;
167+ // ---cut-before---
168+ import type { Federation } from " @fedify/fedify" ;
169+ import { WorkersKvStore } from " @fedify/fedify/x/cfworkers" ;
170+
171+ export default {
172+ async fetch(request , env , ctx ) {
173+ const federation: Federation <void > = await builder .build ({
174+ kv: new WorkersKvStore (env .KV_BINDING ),
175+ });
176+ return await federation .fetch (request , { contextData: undefined });
177+ }
178+ } satisfies ExportedHandler <{ KV_BINDING: KVNamespace <string > }>;
179+ ~~~~
180+
181+ > [ !NOTE]
182+ > Since your ` KVNamespace ` is not bound to a global variable, but rather
183+ > passed as an argument to the ` fetch() ` method, you need to instantiate
184+ > your ` Federation ` object inside the ` fetch() ` method.
185+ >
186+ > For better organization, you probably want to use a builder pattern to
187+ > register your dispatchers and listeners before instantiating the ` Federation `
188+ > object. See the [ * Builder pattern for structuring*
189+ > section] ( ./federation.md#builder-pattern-for-structuring ) for details.
190+
191+ [ Cloudflare Workers ] : https://workers.cloudflare.com/
192+ [ Cloudflare Workers KV ] : https://developers.cloudflare.com/kv/
193+
145194
146195Implementing a custom ` KvStore `
147196-------------------------------
0 commit comments