/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/utils/src/lib/LruCache.ts
32 строки
774 B
Mitja Bezenšek
fix(memory): clean up module-level state leaks after editor unmount (#8604)
28 апр 2026, 10:53
Не верифицирован
28 апр 2026, 10:53
5dfc426
Код
Авторство
О чём код?
/** Simple LRU cache backed by a Map's insertion-order iteration. @public */ export class LruCache<K, V> { private map = new Map<K, V>() constructor(private maxSize: number) {} get(key: K): V | undefined { if (!this.map.has(key)) return undefined const value = this.map.get(key)! // Move to most-recent position this.map.delete(key) this.map.set(key, value) return value } set(key: K, value: V): void { if (this.map.has(key)) this.map.delete(key) this.map.set(key, value) if (this.map.size > this.maxSize) { // Evict oldest entry this.map.delete(this.map.keys().next().value!) } } has(key: K): boolean { return this.map.has(key) } // eslint-disable-next-line tldraw/no-setter-getter get size(): number { return this.map.size } }