UNPKG

@foxpage/foxpage-manager

Version:

foxpage resource manager

66 lines (65 loc) 1.55 kB
import { Logger, ResourceCache } from '@foxpage/foxpage-types'; export type DiskCacheOption = { appId: string; type: string; logger?: Logger; }; /** * disk cache * * @export * @class DiskCache * @implements {ResourceCache<T>} * @template T */ export declare class DiskCache<T> implements ResourceCache<T> { diskCache: Map<string, { filePath: string; hash: string; }>; private appId; private type; private logger?; constructor(opt: DiskCacheOption); getCurCount(): number; /** * set disk cache * * @param {string} id * @param {T} resource * @return {*} {Promise<void>} */ set(id: string, resource: T): Promise<void>; /** * get content from disk * * @param {string} id * @return {*} {(Promise<T | null | undefined>)} */ get(id: string): Promise<T | null | undefined>; /** * check if exist the content * * @param {string} id * @return {*} {Promise<boolean>} */ has(id: string): Promise<boolean>; /** * update delete status for delete action * * @param {string} id * @param {boolean} all true: remove all files of the dir, false: only remove the invalid files * @return {*} {Promise<void>} * @memberof DiskCache */ delete(id: string, all?: boolean): Promise<void>; private getRootDir; private generateFilePath; private computeMD5Hash; private getFiles; /** * destroy the instance * */ destroy(): void; }