Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

schiacciata/cf-workers-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

26 Commits

Repository files navigation

cf-workers-storage

πŸ—‚ Set of utilities to help you manage your cloudflare worker storages

Avaible classes:

β€’ CacheManager.ts

β€’ KVManager.ts

β€’ R2Manager.ts

Installation

npm i schiacciata/cf-workers-storage

Example

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}`);
	},
};

About

πŸ—‚ Set of utilities to help you manage your cloudflare worker storages

Topics

Resources

Stars

Watchers

Forks

Packages

Contributors

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /