import type { CacheSpec } from "../../types/00_CacheSpec.js"; import type { StoreGetManyResult } from "../../types/06_Store.js"; import { type AnyParams, type AnyValidators, type EntryForId, type Logger, type NormalizedParams, type Store, type StoreEntryInput, type StoreGetManyRequest } from "../../types/index.js"; /** * A {@link Store} that persists entries as JSON files in a single directory -- * one file per `(id, variantKey)` tuple. Designed for use cases where the * cache lives on disk and is portable across process invocations (e.g., * downloaded/uploaded as a CI artifact between runs). * * Files are named by a SHA-256 hash of `jsonStringify([id, variantKey])`, so * filenames are always filesystem-safe and stable for the same logical key. * Writes go through a `.tmp` file + rename so a crashed process never leaves a * half-written entry behind. * * The store keeps an in-memory index of every non-expired file, populated * lazily on the first `get`/`getMany`/`store`/`delete` call. Initial scans * are O(files-on-disk); subsequent operations are O(variants-for-that-id). * * Like {@link MemoryStore}, this store uses the simple "filter in JS" approach * to vary matching via {@link variantMatchesRequest}. That's appropriate here: * disks small enough to fit in this store's intended use (CI artifacts, * developer-machine caches) don't benefit from query-side filtering. */ export default class FileStore implements Store { #private; /** * @param opts.directory The directory to persist cache files in. Created * on first write if it doesn't already exist. The store assumes * ownership of the directory's contents: any pre-existing files that * don't parse as cache records are ignored, but `delete(id)` may remove * files within it. * * @param opts.fallbackDeleteAfter When the cache asks the store to keep an * entry "forever" (`Infinity` seconds), the store will instead keep it * for this many seconds. Defaults to 30 days, which is long enough to * span typical CI cache retention windows but short enough that * abandoned entries don't accumulate forever. * * @param opts.logger Custom logger. Defaults to the package's debug-based * logger. */ constructor(opts: { directory: string; fallbackDeleteAfter?: number; logger?: Logger; }); get(id: Id, normalizedParams: NormalizedParams): Promise[]>; getMany[]>(requests: Reqs): Promise>; store(entries: readonly StoreEntryInput[]): Promise; delete(id: Spec["id"]): Promise; close(): Promise; [Symbol.asyncDispose](): Promise; } //# sourceMappingURL=FileStore.d.ts.map