Cloudflare KV adapter for Schematic SDK
npm install @schematichq/schematic-typescript-cloudflareCloudflare KV cache adapter for Schematic SDK.
``bash`
npm install @schematichq/schematic-typescript-cloudflare
`typescript
import { SchematicClient } from "@schematichq/schematic-typescript-node";
import { CloudflareKVCache } from "@schematichq/schematic-typescript-cloudflare";
// Inside a Cloudflare Worker
export default {
async fetch(request, env, ctx) {
// Create a CloudflareKVCache instance
const cache = new CloudflareKVCache
ttl: 1000 60 60, // 1 hour
});
// Initialize Schematic with the cache
const schematic = new SchematicClient({
apiKey: env.SCHEMATIC_API_KEY,
cacheProviders: {
flagChecks: [cache],
}});
// Your application logic...
}
};
`
`typescript`
interface KVNamespace {
get
put(key: string, value: string, options?: { expirationTtl?: number }): Promise
delete(key: string): Promise
list(options?: { prefix?: string }): Promise<{ keys: Array<{ name: string }> }>;
}
The interface matches the Cloudflare Workers KV API, including support for typed get operations for enhanced type safety.
`typescript
class CloudflareKVCache
constructor(
kvNamespace: KVNamespace,
options?: {
keyPrefix?: string; // Default: 'schematic:'
ttl?: number; // Default: 5000ms
}
);
get(key: string): Promise
set(key: string, value: T, ttlOverride?: number): Promise
delete(key: string): Promise
deleteAllExcept(keysToKeep: string[]): Promise
clear(): Promise
}
``
MIT