const _cache = {};
const minute = 60 * 1000;
const cache = (key, fn, minutes) => {
if (_cache[key] && _cache[key].expires >= new Date()) {
return _cache[key].data;
}
else
{
const data = fn();
if (data) {
_cache[key] = {
expires: new Date(new Date().getTime() + (minutes * minute)),
data: data
};
}
return data;
}
};
const removeFromCache = key => {
if (_cache[key]) {
delete _cache[key];
}
};
177700cookie-checkJavascript: Simple cache function