@daisugi/kintsugi
Version:
Kintsugi is a set of utilities to help build a fault tolerant services.
21 lines • 1.15 kB
TypeScript
import type { AnzenAnyResult, AnzenResultFn } from '@daisugi/anzen';
interface WithCacheOpts {
version?: string;
maxAgeMs?: number;
cacheStore?: CacheStore;
buildCacheKey?(fnHash: number, version: string, args: any[]): string;
calculateCacheMaxAgeMs?(maxAgeMs: number): number;
shouldCache?(response: AnzenAnyResult<any, any>): boolean;
shouldInvalidateCache?(args: any[]): boolean;
}
export interface CacheStore {
get(cacheKey: string): AnzenAnyResult<any, any> | Promise<AnzenAnyResult<any, any>>;
set(cacheKey: string, value: any, maxAgeMs: number): AnzenAnyResult<any, any> | Promise<AnzenAnyResult<any, any>>;
}
export declare function buildCacheKey(fnHash: number, version: string, args: any[]): string;
export declare function calculateCacheMaxAgeMs(maxAgeMs: number): number;
export declare function shouldInvalidateCache(): boolean;
export declare function shouldCache(response: AnzenAnyResult<any, any>): boolean;
export declare function withCache(fn: AnzenResultFn<any, any>, opts?: WithCacheOpts): (this: unknown, ...args: any[]) => Promise<any>;
export {};
//# sourceMappingURL=with_cache.d.ts.map