s2maps-gpu
Version:
S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.
48 lines (47 loc) • 1.34 kB
TypeScript
/**
* # Cache System
*
* ## Description
* A cache of values with a max size to ensure that too much old data is not stored.
* The deletion system uses the FIFO policy
*
* ## Usage
*
* ```ts
* import { Cache } from 'gis-tools-ts';
*
* const onDelete = (key: string, value: string) => {
* console.log(`Deleted key ${key} with value ${value}`);
* };
* const cache = new Cache<string, string>(10, onDelete);
* cache.set('key', 'value');
* console.log(cache.get('key')); // 'value'
* cache.delete('key');
* ```
*/
export declare class Cache<K, V> extends Map<K, V> {
private readonly maxSize;
private onDelete?;
order: K[];
/**
* @param maxSize - the max size of the cache before dumping old data
* @param onDelete - if provided, will be called when a value is removed
*/
constructor(maxSize: number, onDelete?: ((key: K, value: V) => void) | undefined);
/**
* @param key - the offset position in the data
* @param value - the value to store
* @returns this
*/
set(key: K, value: V): this;
/**
* @param key - the offset position in the data
* @returns - the value if found
*/
get(key: K): V | undefined;
/**
* @param key - the offset position in the data
* @returns - true if found
*/
delete(key: K): boolean;
}