@patreon/studio
Version:
Patreon Studio Design System
27 lines • 678 B
JavaScript
export class LRUCache {
cache;
cacheSize;
constructor(config) {
this.cacheSize = config?.size ?? 100;
this.cache = new Map();
}
get(key) {
const value = this.cache.get(key);
this.cache.delete(key);
this.cache.set(key, value);
return this.cache.get(key);
}
set(key, value) {
if (this.cache.has(key)) {
this.cache.delete(key);
}
this.cache.set(key, value);
if (this.cache.size > this.cacheSize) {
this.cache.delete(this.cache.keys().next().value);
}
}
size() {
return this.cache.size;
}
}
//# sourceMappingURL=lru.js.map