/
vshmidt
/
label-studio
Обзор
Документация
Войти
/
vshmidt
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
web/libs/editor/src/lib/AudioUltra/Common/Cacheable.ts
29 строк
533 B
Raul Martin
refactor: echo 27: Introducing biome (#5759)
29 апр 2024, 11:39
Не верифицирован
29 апр 2024, 11:39
2660ec9
Код
Авторство
О чём код?
export class Cacheable { private cache = new Map<string, any>(); createKey(...args: any[]) { if (args.length === 1) { return args[0].toString(); } return args.join(":"); } clearCache() { this.cache.clear(); } cached(key: number | string | Array<string | number>, fn: () => any) { const cacheKey = this.createKey(key); if (this.cache.has(cacheKey)) { return this.cache.get(cacheKey); } const result = fn(); this.cache.set(cacheKey, result); return result; } }