UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

56 lines 1.88 kB
/** * Options for storing a cache value. */ export interface CacheSetOptions { /** * Time-to-live in seconds. Omit this for a value that does not expire. */ ttlSeconds?: number; } /** * App-facing string cache port. * * Values are intentionally strings so adapters can map cleanly to Redis, * Upstash, and other key/value stores. Serialize structured values at the app * boundary. */ export interface CachePort { /** * Return a fresh value for `key`, or `null` when missing or expired. */ get(key: string): Promise<string | null>; /** * Store a string value. */ set(key: string, value: string, options?: CacheSetOptions): Promise<void>; /** * Delete a cache key. * * @returns `true` when the key existed. */ delete(key: string): Promise<boolean>; /** * Return whether a fresh value exists for `key`. */ has(key: string): Promise<boolean>; /** * Return a cached value or compute, store, and return a new value. * * Implementations are not required to provide single-flight behavior. If * concurrent cache fills matter, choose an adapter that documents that * guarantee or protect the factory at the application layer. */ remember(key: string, factory: () => Promise<string>, options?: CacheSetOptions): Promise<string>; } /** * Create an in-memory cache for tests, examples, and single-process * development. * * This adapter is not durable or distributed. Values are lost when the process * exits and are not shared across workers, regions, or serverless invocations. * * @param initialValues - Optional initial string values without TTL. * @returns A cache port backed by a local `Map`. */ export declare function createMemoryCache(initialValues?: Record<string, string>): CachePort; //# sourceMappingURL=cache.d.ts.map