CACHE WITH TIME LIMIT in LeetCode | 30 Days of JavaScript

preview_player
Показать описание
Code in comments
Рекомендации по теме
Комментарии
Автор

CODE:
var TimeLimitedCache = function() {
this.cache = new Map();
this.timeout = new Map();
};

= function(key, value, duration) {
const checked = this.cache.has(key);

if(checked){

}

this.cache.set(key, value);

const time = setTimeout(() => {
this.cache.delete(key);
this.timeout.delete(key);
}, duration);

this.timeout.set(key, time);

return checked;
};

= function(key) {
if(this.cache.has(key)){
return this.cache.get(key);
}

return -1;
};

= function() {
return this.cache.size;
};

Westerden
join shbcf.ru