@connected/react
Version:
The hassle free way to call your server-side code
41 lines • 1.01 kB
JavaScript
import tinyLru, {} from 'tiny-lru';
export default class Lru {
eventListener;
lru;
constructor(initialData, maxSize, eventListener) {
this.eventListener = eventListener;
this.lru = tinyLru(maxSize || 500);
if (initialData) {
const keys = Object.keys(initialData);
keys.forEach((key) => {
this.set(key, initialData[key]);
});
}
}
has(key) {
return !!this.get(key);
}
get(key) {
return this.lru.get(key);
}
set(key, value) {
this.lru.set(key, value);
this.eventListener?.('set', key, value);
return this;
}
clear() {
this.lru.clear();
this.eventListener?.('clear');
return this;
}
delete(key) {
this.lru.delete(key);
this.eventListener?.('delete', key);
return this;
}
isEmpty() {
const { size } = this.lru;
return size === 0;
}
}
//# sourceMappingURL=lru.js.map