/** * @file `createBrowserTtlCache` — browser-safe sibling of `createTtlCache` * (`./store`). Same two-tier design and `TtlCache` contract, but the * persistent tier is an injected `TtlCacheStorage` adapter (wrap * `chrome.storage.local`, `sessionStorage` / `localStorage`, IndexedDB, …) * instead of cacache, so the module's import graph stays primordials-only — * safe for Chrome MV3 service workers, content scripts, popups, and web * workers. Shared semantics live in `./shared` (one owner, so the node * and browser stores cannot drift): TTL default, clock-skew detection, LRU * memo eviction via Map insertion order, prefix namespacing, wildcard * matching. `getOrFetch` deduplicates concurrent fetches for the same key to * protect against a thundering herd, and single-key methods throw on `*`. * Differences from `./store`, whose cacache-specific pieces don't map here: * * - No cacache `ls.stream` — `getAll` / `deleteAll` / `clear` enumerate the * persistent tier only when the adapter provides the optional `keys()` * (e.g. `chrome.storage.local.get(null)`, `sessionStorage.key(i)`). Without * it they still cover the memo tier, and delete those memo keys from * storage too; storage-only entries from previous sessions are then * unreachable by wildcard but still expire per-entry on read. * - No storage supplied ⇒ memo-only cache; all operations stay correct. * - A corrupt or shape-invalid storage entry is treated as a miss and deleted * best-effort; storage failures never throw — the memo tier is the source * of truth, mirroring store.ts's cacache error handling. */ import type { BrowserTtlCacheOptions, TtlCache } from './types.js'; /** * Create a browser-safe TTL cache instance. Same contract as * `createTtlCache`, with the persistent tier backed by the injected * `storage` adapter. Omit the adapter for a memo-only cache. * * @example * ;```typescript * const cache = createBrowserTtlCache({ * prefix: 'my-extension', * storage: { * async getItem(key) { * return (await chrome.storage.local.get(key))[key] * }, * async keys() { * return Object.keys(await chrome.storage.local.get(null)) * }, * async removeItem(key) { * await chrome.storage.local.remove(key) * }, * async setItem(key, value) { * await chrome.storage.local.set({ [key]: value }) * }, * }, * ttl: 60_000, * }) * await cache.set('key', { value: 42 }) * const data = await cache.get('key') // { value: 42 } * ``` */ export declare function createBrowserTtlCache(options?: BrowserTtlCacheOptions | undefined): TtlCache;