chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
20 lines (19 loc) • 638 B
TypeScript
type Fetcher<T> = () => Promise<T> | T;
export declare class TtlCache<T> {
private readonly fetcher;
private readonly ttlMs;
private cachedValue;
private expiresAt;
private pendingPromise;
constructor(fetcher: Fetcher<T>, ttlSeconds: number);
/**
* Fetches a value, optionally using the cache.
*
* @param useCache – if true, return the cached value when still fresh;
* if false, always re-fetch, cache & return the new value.
*/
get(useCache: boolean): Promise<T>;
/** Clear both the cached value and any in-flight fetch. */
clear(): void;
}
export {};