liveperson-functions-client
Version:
JavaScript client for LivePerson Functions.
41 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IsImplementedCache = void 0;
class IsImplementedCache {
constructor(cacheDuration) {
this.cacheDuration = cacheDuration;
this.cache = [];
}
get(eventName, skillId) {
const event = this.cache.find(e => {
return skillId
? e.name === eventName && e.skillId === skillId
: e.name === eventName;
});
if (event) {
if (event.exp > Date.now())
return event;
this.removeFromCache(event);
}
return undefined;
}
add(eventName, isImplemented, skillId) {
const event = this.get(eventName, skillId);
if (event) {
this.removeFromCache(event);
}
const newEvent = {
name: eventName,
exp: Date.now() + this.cacheDuration * 1000,
isImplemented,
skillId,
};
this.cache.push(newEvent);
}
removeFromCache(event) {
const index = this.cache.indexOf(event);
this.cache.splice(index, 1);
}
}
exports.IsImplementedCache = IsImplementedCache;
//# sourceMappingURL=isImplementedCache.js.map