@kth/cortina-block
Version:
Node.js module for fetching Cortina blocks and optionally cache using Redis.
20 lines (19 loc) • 534 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoryCache = void 0;
const STORE = {};
const set = (name, value, ttl_seconds) => {
STORE[name] = { value, expires: Date.now() + ttl_seconds * 1000 };
};
const get = name => {
if (!STORE[name]) {
return undefined;
}
const { expires, value } = STORE[name];
if (Date.now() > expires) {
return undefined;
}
return value;
};
exports.memoryCache = { get, set };
module.exports = { memoryCache: { get, set } };