/** * @b9g/cache - Universal Cache API implementation * * Provides HTTP-aware caching with PostMessage coordination for worker environments */ /** * Cache query options for matching requests * Based on the Cache API specification */ export interface CacheQueryOptions { /** Ignore the search portion of the request URL */ ignoreSearch?: boolean; /** Ignore the request method */ ignoreMethod?: boolean; /** Ignore the Vary header */ ignoreVary?: boolean; /** Custom cache name for scoped operations */ cacheName?: string; } /** * Convert RequestInfo or URL to Request */ export declare function toRequest(request: RequestInfo | URL): Request; /** * Abstract Cache class implementing the Cache API interface * Provides shared implementations for add() and addAll() while requiring * concrete implementations to handle the core storage operations * * All cache implementations must follow the constructor signature: * constructor(name: string, options?: CacheOptions) */ export declare abstract class Cache implements globalThis.Cache { /** * Returns a Promise that resolves to the response associated with the first matching request */ abstract match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise; /** * Puts a request/response pair into the cache */ abstract put(request: RequestInfo | URL, response: Response): Promise; /** * Finds the cache entry whose key is the request, and if found, deletes it and returns true */ abstract delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise; /** * Returns a Promise that resolves to an array of cache keys (Request objects) */ abstract keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise; /** * Takes a URL, retrieves it and adds the resulting response object to the cache * Shared implementation using fetch() and put() */ add(request: Request): Promise; /** * Takes an array of URLs, retrieves them, and adds the resulting response objects to the cache * Shared implementation using add() */ addAll(requests: Request[]): Promise; /** * Returns a Promise that resolves to an array of all matching responses * Default implementation using keys() and match() - can be overridden for efficiency */ matchAll(request?: Request, options?: CacheQueryOptions): Promise; } /** * Generate a cache key from a Request, string URL, or URL object * Normalizes the request for consistent cache key generation */ export declare function generateCacheKey(request: RequestInfo | URL, options?: CacheQueryOptions): string; /** * Constructor type for Cache implementations * All cache classes must accept name as first parameter and optional options as second */ export type CacheConstructor = new (name: string, options?: O) => T; /** * Factory function for creating Cache instances based on cache name */ export type CacheFactory = (name: string) => Cache | Promise; /** * CustomCacheStorage implements CacheStorage interface with a configurable factory * The factory function receives the cache name and can return different cache types */ export declare class CustomCacheStorage implements CacheStorage { #private; constructor(factory: CacheFactory); /** * Matches a request across all caches */ match(request: Request, options?: CacheQueryOptions): Promise; /** * Opens a cache with the given name * Returns existing instance if already opened, otherwise creates a new one */ open(name: string): Promise; /** * Returns true if a cache with the given name exists (has been opened) */ has(name: string): Promise; /** * Deletes a cache with the given name */ delete(name: string): Promise; /** * Returns a list of all opened cache names */ keys(): Promise; /** * Dispose of all cache instances * Calls dispose() on each cache if it exists (e.g., RedisCache needs to close connections) */ dispose(): Promise; /** * Handle cache messages from worker threads (PostMessageCache coordination) */ handleMessage(worker: any, message: any): Promise; }