import LRU from 'lru-cache'; /** * Small utility around an LRU cache that gives us some features: * - Promisification: Async ready to easily change to a memcached/redis implementation * - Improved get method, to make more expressive usage of the pattern "if not found * in the cache, go get it, store in the cache, and return the value" * - Funnel values: Promises are stored and returned, so if the value for a key * is being obtained while another get is requested, the promise of the value is returned * so only one request for value is done */ export declare class Cache { lru: LRU>; constructor(opt?: LRU.Options>); /** * Sets a value in the cache * * When the value is a promise, and the value rejects, it will be automatically * dropped from the cache * * @returns {Promise.} Success on setting the value on the cache */ set(key: K, value: Promise, maxAge?: number): Promise; /** * Deletes a value from the cache * * @param {String} key * @returns {Promise.<*>} */ del(key: K): Promise; /** * Clear the cache entirely, throwing away all values. * * @returns {Promise.<*>} */ reset(): Promise; /** * Prunes the cache, deleting expired items from the cache */ prune(): Promise; } export interface Cache { /** * Gets a value from the cache. When an optional getter method is provided, * it will be called when there is a cache miss to get the value and store * it in the cache. * When the getter method throws/rejects, it will be propagated down the chain * * ```js * // Old Way (Sync code) * let value = cache.get(key); * if (!value) { * value = calculateValue(); * cache.put(key, value); * } * return value; * ``` * that becomes * ```js * return cache.get(key, calculateValue); * ``` * * @param key the cache entry key * @param getter the function to call when a value is not found * in the cache. Return promise or a discrete value, that will be * stored in the cache for that key * @returns the cache entry */ get(key: K, getter?: () => Promise | V, maxAge?: number): Promise; /** * Gets a value from the cache. * * @param key the cache entry key * @returns the cache entry */ get(key: K): Promise; }