type Timestamped = { readonly value: T; readonly timestamp: number; }; type Returned = Timestamped & { readonly type: "fresh" | "cached" | "fallback"; }; /** Handles caching a value for a given duration to avoid repeated fetches. */ export declare class Cached { readonly cacheDuration: number; readonly fallbackDuration: number; private readonly _fetch; private readonly _getCurrentTimestamp; private _data; constructor({ fetch, getCurrentTimestamp, cacheDuration, fallbackDuration, }: { /** The function that does the expensive fetch. */ fetch: () => Promise; /** * Provides the current timestamp. The timestamp can be measured in any unit * of time, as long as it matches the unit used for cache duration and * fallback duration. */ getCurrentTimestamp: () => number; /** How long to cache data before attempting to fetch fresh again. */ cacheDuration: number; /** * How long expired data can continue to be used in the event of a failed * fetch. Default: 0 (i.e. never fallback). */ fallbackDuration?: number; }); /** * Get the value. Will throw if the fetch fails and the cached data is * unavailable for older than the fallback duration. */ get(): Promise>; /** * Ignore the cache the fetch the value. The result will be cached for future * access. */ fetch(): Promise>; /** * Clear the cache and force the value to be re-fetched on next access, * regardless of age. */ clear(): void; private _getCachedData; } export {};