@songbaek/fifo-map
Version:
47 lines (46 loc) • 1.2 kB
TypeScript
export interface FifoMapProps {
maxSize: number;
}
/**
* FIFO Map Cache.
*/
export declare class FifoMap<KeyType, ValueType> {
private _db;
private _fifoKeys;
private _maxSize;
constructor(props: FifoMapProps);
get size(): number;
/**
* Get item.
* @param key key
* @returns `cached value`, if input key matches.\
`undefined`, if it does not exist.
*/
get: (key: KeyType) => ValueType | undefined;
/**
* Put item. \
* It also deletes item as FIFO only when cache is full.
* @param key key
* @param value value
* @returns `old item`, if cache is full and delete an item done. \
* `undefined`, if cache is not full and only put done.
*/
put: (key: KeyType, value: ValueType) => {
key: KeyType;
value: ValueType & ({} | null);
} | undefined;
/**
* Delete item.
* @param key key
* @returns `deleted item`, if key exists and deleted.\
* `undefined`, if key does not exist.
*/
delete: (key: KeyType) => {
key: KeyType;
value: ValueType & ({} | null);
} | undefined;
/**
* Clear all.
*/
clear: () => void;
}