UNPKG

@modern-js/runtime-utils

Version:

A Progressive React Framework for modern web development.

46 lines (45 loc) 1.48 kB
export declare const CacheSize: { readonly KB: 1024; readonly MB: number; readonly GB: number; }; export declare const CacheTime: { readonly SECOND: 1000; readonly MINUTE: number; readonly HOUR: number; readonly DAY: number; readonly WEEK: number; readonly MONTH: number; }; export type CacheStatus = 'hit' | 'stale' | 'miss'; export interface CacheStatsInfo { status: CacheStatus; key: string | symbol; params: any[]; result: any; } interface CacheOptions { tag?: string | string[]; maxAge?: number; revalidate?: number; getKey?: <Args extends any[]>(...args: Args) => string; customKey?: <Args extends any[]>(options: { params: Args; fn: (...args: Args) => any; generatedKey: string; }) => string | symbol; onCache?: (info: CacheStatsInfo) => void; } interface CacheConfig { maxSize?: number; unstable_shouldDisable?: ({ request, }: { request: Request; }) => boolean | Promise<boolean>; } export declare function configureCache(config: CacheConfig): void; export declare function generateKey(args: unknown[]): string; export declare function cache<T extends (...args: any[]) => Promise<any>>(fn: T, options?: CacheOptions): T; export declare function withRequestCache<T extends (req: Request, ...args: any[]) => Promise<any>>(handler: T): T; export declare function revalidateTag(tag: string): void; export declare function clearStore(): void; export {};