r3bl-ts-utils
Version:
The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu
16 lines (15 loc) • 673 B
TypeScript
export interface Cache<K, V> {
name: string;
maxSize: number;
size: number;
evictionPolicy: EvictionPolicy;
get: (arg: K) => V | undefined;
getAndComputeIfAbsent: (arg: K, populateFn: ComputeValueForKeyFn<K, V>) => V;
getAndComputeIfAbsentAsync: (arg: K, populateAsyncFn: ComputeValueForKeyAsyncFn<K, V>) => Promise<V>;
put: (arg: K, value: V) => void;
contains: (arg: K) => boolean;
clear: () => void;
}
export declare type EvictionPolicy = "least-frequently-used" | "least-recently-used";
export declare type ComputeValueForKeyFn<K, V> = (arg: K) => V;
export declare type ComputeValueForKeyAsyncFn<K, V> = (arg: K) => Promise<V>;