UNPKG

mollitia

Version:

JavaScript Resilience Library

64 lines (62 loc) 1.99 kB
import { Module, ModuleOptions } from './index.js'; import { Circuit, CircuitFunction } from '../circuit.js'; type AdjustCacheParamsCallback = (func: CircuitFunction, ...params: any[]) => any; /** * Properties that customizes the cache behavior. */ export declare abstract class CacheOptions extends ModuleOptions { /** * The amount of time during which a cached result is considered valid. */ ttl?: number; /** * The amount of time before the cache cleans itself up. */ cacheClearInterval?: number; /** * The attribute name indicating if data is retrieved from cache or not */ getInformationFromCache?: boolean; /** * A filtering callback, to modify the parameters used for Cache Key. * @returns The modified parameters */ adjustCacheParams?: AdjustCacheParamsCallback; } type CacheT<T> = T & { _mollitiaIsFromCache: boolean; }; /** * The Cache Module, that allows to cache result for an amount of time. */ export declare class Cache extends Module { /** * The amount of time during which a cached result is considered valid. */ ttl: number; /** * The attribute name indicating if data is retrieved from cache or not */ getInformationFromCache: boolean; /** * A filtering callback, to modify the parameters used for Cache Key. */ adjustCacheParams: AdjustCacheParamsCallback | null; private cache; private _cacheClearInterval; private _cacheInterval; /** * Get the amount of time before the cache cleans itself up. */ get cacheClearInterval(): number; /** * Set the amount of time before the cache cleans itself up. */ set cacheClearInterval(interval: number); constructor(options?: CacheOptions); execute<T>(circuit: Circuit, promise: CircuitFunction, ...params: any[]): Promise<T | CacheT<T>>; dispose(): void; private _promiseCache; private _initializeInterval; } export {};