UNPKG

@file-cache/core

Version:

A cache for file metadata or file content.

79 lines 2.22 kB
/// <reference types="node" /> import { CreateCacheKeyGenerator } from "./createCacheKey.js"; export type { CreateCacheKeyGenerator } from "./createCacheKey.js"; export type CreateCacheOptions = { /** * The name of the cache * It is used for the cache directory name * */ name: string; /** * - content: Using the hash value of file content * - Slow but accurate * - metadata: Using the metadata of file * - Fast but not accurate * - It can not be used in CI env */ mode: "content" | "metadata"; /** * The key generators for cache file */ keys: CreateCacheKeyGenerator[]; /** * Custom cache directory. * Default: node_modules/.cache/<name> */ cacheDirectory?: string; /** * If true, the cache will not be used. * Default: false * * - getAndUpdateCache(): return { changed: true } * - delete(): nope. return true. * - clear(): nope. return true. * - reconcile(): nope. return true. */ noCache?: boolean; }; export type DeleteCacheOptions = Omit<CreateCacheOptions, "noCache">; /** * Delete cache file * Note: It does not clear in-memory cache in the cache. * @param options */ export declare const deleteCacheFile: (options: DeleteCacheOptions) => Promise<boolean>; /** * Create cache instance * @param options */ export declare const createCache: (options: CreateCacheOptions) => Promise<import("./CacheInterface.js").CacheInterface | { /** * Experimental method * @param cb */ try(cb: () => Promise<void>): Promise<void>; /** * Get cache status and update the cache value * You need to confirm the status via call `reconcile()` after that * @param filePath */ getAndUpdateCache(filePath: string | URL): Promise<{ readonly error: unknown; readonly changed: boolean; }>; /** * Delete cache value for the key * @param filePath */ delete(filePath: string): Promise<boolean>; /** * Clear cache values */ clear(): Promise<void>; /** * Confirm the changes */ reconcile(): Promise<boolean>; }>; //# sourceMappingURL=index.d.ts.map