import { CacheStorageConfig, CreateStorageFn, ICacheStorage } from './ICacheStorage'; /** * Configuration options specific to KVCacheStorage */ export interface KVCacheStorageConfig extends CacheStorageConfig { /** * Disable the local in-memory cache layer. * When enabled (default), a local TTLCache is used as a synchronous first-level cache * before falling back to KV. This is intended for use in workers where the local * cache only exists for the duration of a single request, providing fast access * for repeated reads within the same request without hitting KV multiple times. */ disableLocalCache?: boolean; } /** * Cloudflare KV namespace interface */ export interface KVNamespace { get(key: string, options?: { type?: 'text' | 'json' | 'arrayBuffer' | 'stream'; }): Promise; put(key: string, value: string, options?: { expirationTtl?: number; expiration?: number; metadata?: unknown; }): Promise; delete(key: string): Promise; list(options?: { prefix?: string; limit?: number; cursor?: string; }): Promise<{ keys: { name: string; expiration?: number; metadata?: unknown; }[]; list_complete: boolean; cursor?: string; }>; } /** * Cloudflare KV-backed cache storage implementation * Implements ICacheStorage from @towns-labs/web3 for use as a cache backend * * This implementation includes an optional local in-memory cache layer (enabled by default) * that sits in front of KV. This is intended for use in Cloudflare Workers or similar * serverless environments where the local cache only exists for the duration of a single * request. This provides fast access for repeated reads within the same request without * hitting KV multiple times, while still benefiting from KV's persistence across requests. */ export declare class KVCacheStorage implements ICacheStorage { private readonly kv; private readonly keyPostfix; private readonly defaultTtlMs; private readonly minKVTtlSeconds; /** * Local in-memory cache that serves as a synchronous first-level cache before KV. * In a worker context, this cache only exists for the duration of the request, * providing fast repeated access without additional KV reads. * TTLCache handles expiration automatically via its built-in TTL support. */ private readonly localCache; constructor(kv: KVNamespace, config: KVCacheStorageConfig); private getKey; get(key: string): Promise; set(key: string, value: V, ttlMs?: number): Promise; delete(key: string): Promise; } /** * Create a factory function that creates KV-backed cache storage instances * Creates a factory function for KV-backed cache storage instances * * @param kv The Cloudflare or Hosting provider KV namespace * @param options Optional configuration for the KV storage (e.g., disableLocalCache) * @returns A factory function compatible with CreateStorageFn */ export declare function createKVStorageFactory(kv: KVNamespace, options?: Pick): CreateStorageFn; //# sourceMappingURL=KVCacheStorage.d.ts.map