UNPKG

transitory

Version:

In-memory cache with high hit rates via LFU eviction. Supports time-based expiration, automatic loading and metrics.

35 lines (34 loc) 1.16 kB
import { Cache } from '../Cache'; import { CommonCacheOptions } from '../CommonCacheOptions'; import { KeyType } from '../KeyType'; import { WrappedCache } from '../WrappedCache'; import { Loader } from './Loader'; import { LoadingCache } from './LoadingCache'; declare const DATA: unique symbol; /** * Options available for a loading cache. */ export interface LoadingCacheOptions<K extends KeyType, V> extends CommonCacheOptions<K, V> { loader?: Loader<K, V> | undefined | null; parent: Cache<K, V>; } /** * Extension to another cache that will load items if they are not cached. */ export declare class DefaultLoadingCache<K extends KeyType, V> extends WrappedCache<K, V> implements LoadingCache<K, V> { private [DATA]; constructor(options: LoadingCacheOptions<K, V>); /** * Get cached value or load it if not currently cached. Updates the usage * of the key. * * @param key - * key to get * @param loader - * optional loader to use for loading the object * @returns * promise that resolves to the loaded value */ get(key: K, loader?: Loader<K, V>): Promise<V>; } export {};