π Set of utilities to help you manage your cloudflare worker storages
Avaible classes:
β’ CacheManager.ts
β’ KVManager.ts
β’ R2Manager.ts
npm i schiacciata/cf-workers-storage
import { KVManager, StorageEnv } from '@schiacciata/cf-workers-storage'; export interface Env extends StorageEnv { CUSTOM_KV: KVNamespace; //remember to add them in the wrangler.toml file } export default { async fetch( request: Request, env: Env, ctx: ExecutionContext ): Promise<Response> { const kvStorage = new KVManager({ context: ctx, env: env, kvName: 'DEFAULT_KV' }); const newKV = 'CUSTOM_KV'; const key = request.url; const result = await kvStorage.get({ key, kvName: newKV }); if (result) return new Response(`Key ${key} has value ${result}`); const value = request.method; kvStorage.set({ key, kvName: newKV, value, }); return new Response(`Saved value ${value} for key ${key} in kv ${newKV}`); }, };