transitory
Version:
In-memory cache with high hit rates via LFU eviction. Supports time-based expiration, automatic loading and metrics.
42 lines (41 loc) • 1.3 kB
TypeScript
import { Cache } from '../Cache';
import { CommonCacheOptions } from '../CommonCacheOptions';
import { KeyType } from '../KeyType';
import { WrappedCache } from '../WrappedCache';
import { Metrics } from './Metrics';
declare const METRICS: unique symbol;
/**
* Options available for a metrics cache.
*/
export interface MetricsCacheOptions<K extends KeyType, V> extends CommonCacheOptions<K, V> {
parent: Cache<K, V>;
}
/**
* Extension to a cache that tracks metrics about the size and hit rate of
* a cache.
*/
export declare class MetricsCache<K extends KeyType, V> extends WrappedCache<K, V> {
private [METRICS];
constructor(options: MetricsCacheOptions<K, V>);
/**
* Get metrics for this cache. Returns an object with the keys `hits`,
* `misses` and `hitRate`. For caches that do not have metrics enabled
* trying to access metrics will throw an error.
*
* @returns
* metrics of cache
*/
get metrics(): Metrics;
/**
* Get the cached value for the specified key if it exists. Will return
* the value or `null` if no cached value exist. Updates the usage of the
* key.
*
* @param key -
* key to get
* @returns
* current value or `null`
*/
getIfPresent(key: K): V | null;
}
export {};