UNPKG

@xchainjs/xchain-util

Version:
27 lines (26 loc) 807 B
/** * Utility class for caching stable data */ export declare class CachedValue<T> { private cachedValue; private cacheTimestamp; private cacheMaxAge; private refreshData; private refreshPromise; /** * @constructor * @param refreshData function that refresh and return the data * @param {number|undefined} cacheMaxAge time in millisecond to expire cache */ constructor(refreshData: (params?: any) => Promise<T>, cacheMaxAge?: number); /** * @private * Validates if internal cache is valid or expired */ private isCacheValid; /** * Returns cached data if valid or request fresh data if cache is invalid * @param params use this params to request data if cache is expired */ getValue(params?: any): Promise<T>; }