UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

42 lines (41 loc) 1.47 kB
/** The Value of the Cache assumes the object has a delete method */ interface CachedObject { delete?: () => void; } /** Cache that keeps the most recently used items and deletes the least recently used items */ export default class Cache<U, T extends CachedObject> extends Map<U, T> { #private; maxCacheSize: number; /** @param maxCacheSize - the maximum size of the cache */ constructor(maxCacheSize?: number); /** * Set a value in the cache. If the cache is full, the least recently used item will be deleted * @param key - the key * @param value - the value * @returns sets the key-value and returns the cache */ set(key: U, value: T): this; /** * Get a value from the cache. If the value exists, it will be placed in the front of the cache * @param key - the key * @returns the value or undefined if the value does not exist */ get(key: U): T | undefined; /** * Get a batch of values from the cache. If the value exists, it will be placed in the front of the cache * @param keys - the keys to get * @returns the values */ getBatch(keys: U[]): T[]; /** @returns all values from the cache */ getAll(): T[]; /** * Delete a value from the cache * @param key - the key to delete * @returns true if the value was deleted */ delete(key: U): boolean; /** Delete all values from the cache */ deleteAll(): void; } export {};