/** * Reads a cached value from IndexedDB by key. * * @param key - Unique cache key * @returns The cached value, or `undefined` if not found */ export declare const readFromCache: (key: string) => Promise; /** * Writes a value to IndexedDB under the given cache key. * * @param value - Object to store; must include `id` and `namespace` */ export declare const writeToCache: (value: T) => Promise; /** * Serializes a value into a stable string for cache key generation. * * - Recursively handles arrays and objects * - Skips functions, promises and undefined values * - Omits keys listed in `ignoreKeys` (only for objects) * - Ensures consistent key ordering for objects * * @param obj - The input to serialize (can be primitive, array, or object) * @param ignoreKeys - Keys to exclude from object serialization * @returns A stable, stringified representation */ export declare const stableSerialize: (obj: unknown, ignoreKeys: string[]) => string; /** * Generates a consistent 64-bit hash key for caching based on input arguments. * * - Serializes objects using `stableSerialize` * - Combines all arguments into a single stable string * * @param ignoreKeys - Keys to exclude from object serialization * @param args - Values to base the cache key on (objects, arrays, or primitives) * @returns A stable 64-bit hash string */ export declare const generateCacheKey: (ignoreKeys: string[], ...args: unknown[]) => Promise; /** * Configuration options for the persistent caching utility. * * @template TResult - Result type returned by the generator function. */ interface BaseCacheConfig { /** * Keys to exclude when generating a stable cache key from input arguments. */ ignoreKeys?: string[]; /** * In-memory cache object, useful for cache sharing across plugins/tabs. */ cache?: Record>; } interface MemoryOnlyCacheConfig extends BaseCacheConfig { /** * Store only in RAM (fast, temporary). No IndexedDB fallback. */ cacheMode: "memory"; /** * No parallel computation needed since memory cache is synchronous. */ parallel?: never; } interface IdbOrBothCacheConfig extends BaseCacheConfig { /** * Store in IndexedDB, or both memory and IndexedDB. */ cacheMode: "idb" | "both"; /** * If true, read from cache and compute in parallel. * Defaults to true. */ parallel?: boolean; } /** * Type-safe configuration for createPersistentCache utility. */ export type CacheConfigType = MemoryOnlyCacheConfig | IdbOrBothCacheConfig; /** * Creates a cached version of an async function with memory and/or persistent caching capabilities. * * ## Features: * - Prevents redundant computations across sessions or concurrent calls * - Shares results between tabs or plugins (Pass external cache object to share in-memory cache across plugins) * - Supports in-memory, IndexedDB, or both as cache targets * - Optional parallel execution of cache read and function compute * - Useful for data generation, API fetches, or any expensive computation * * * ## Parameters * @template Args - Argument types of the generator function * @template Result - Return type of the generator function * * @param generator - The async function to cache (e.g., a fetcher or processor) * @param namespace - A tag used to group related cached entries for cleanup or metrics * @param config - Optional configuration: * - `ignoreKeys` _(string[])_ — Keys to exclude from cache key generation (default: `[]`) * - `cache` _(Record>)_ — External in-memory cache object to sync across plugins/tabs (default: internal default cache) * - `cacheTarget` _(`"memory"` | `"idb"` | `"both"`)_ — Where to store the result: * - `"memory"`: RAM-only; fast but temporary * - `"idb"`: stores in IndexedDB only; avoids memory usage; Useful for processing large data * - `"both"` (default): caches in both RAM and IndexedDB * - `parallel` _(boolean)_ — If true, reads from cache and computes in parallel (default: `true`); * ignored when `cacheTarget` is `"memory"` * * @returns A memoized async function that handles caching automatically. * * @example * const fetchWithCache = createPersistentCache(fetchJson, "remote-data"); * await fetchWithCache("https://example.com/api/data"); */ export declare const createPersistentCache: (generator: (...args: TArgs) => Promise, namespace: string, config?: CacheConfigType) => ((...args: TArgs) => Promise); /** * Deletes stale cache entries from IndexedDB based on age and namespace. * * - Only entries with matching `namespace` are considered * - Entries older than `maxAgeMinutes` (based on `last-accessed` field) are deleted * * Requirements for each entry: * - `namespace: string` set in `createPersistentCache` * - `last-accessed: number` is automatically set by `writeToCache` * * @param maxAgeMinutes - Age threshold in minutes; entries older than this will be removed * @param namespace - Namespace tag to limit cleanup scope */ export declare const simpleCleanup: (maxAgeMinutes: number, namespace: string) => Promise; export {};