@altostra/core
Version:
Core library for shared types and logic
29 lines (28 loc) • 954 B
TypeScript
import type { Logger } from "../Logging";
import type { Maybe } from "../Maybe";
import type { Void } from "../Types";
import type { SaveJsonFileOptions } from "./FS";
import type { AnyTypeValidation } from '@altostra/type-validations';
export interface DataCacheOptions<T> {
cachePath: string;
fetch: () => Promise<T>;
validate: AnyTypeValidation<T>;
saveOptions?: SaveJsonFileOptions;
debugLogger?: Logger;
ttlInSeconds?: number;
}
export declare class DataCache<T> {
#private;
constructor({ cachePath, fetch, validate, debugLogger, saveOptions, ttlInSeconds, }: DataCacheOptions<T>);
updateCache(): Promise<Maybe<T>>;
get(): Promise<Maybe<T>>;
getWithUpdates(): Promise<WithUpdates<T>>;
clearLocal(): Promise<Void>;
private _tryGet;
private _validateData;
}
export interface WithUpdates<T> {
readonly cached: Maybe<T>;
readonly isUpdated: boolean;
getUpdated(): Promise<Maybe<T>>;
}