UNPKG

@voiceiq/web-components

Version:

VoiceIQ Web Component library

55 lines (54 loc) 1.61 kB
export interface RollingCacheUtility { maxLength: number; add: (key: string, value: any) => void; get: (Key: string, defaultValue: any) => any; } /** * A custom implementation of a rolling cache with a max length * @type {RollingCacheUtility} */ declare class RollingCacheUtil { /** * PRIVATE * The actual cache */ _cache: Map<any, any>; /** * Max length of cache */ maxLength: number; /** * Creates a new RollingCache object * * @param {number} maxLength Maximum number of values to hold onto in the cache (Default: 50) */ constructor(maxLength?: number); /** * PRIVATE * Removes the oldest cache entry */ _removeOldest: () => void; /** * Tells whether a cached value is available for given key * * @param {string} key Cache key * @return {bool} True if cached value exists */ has: (key: any) => boolean; /** * Gets the value from cache and returns null/defaultValue on cache miss * * @param {string} key Cache key * @param {any} defaultValue Value to return if it's a miss * @return {any} Cached value if cache hit. DefaultValue/null if cache miss */ get: (key: any, defaultValue?: null) => any; /** * Adds a value to the cache * * @param {string} key Cache key * @param {any} value Value to cache */ add: (key: any, value: any) => void; } export default RollingCacheUtil;