33 lines
672 B
JavaScript
33 lines
672 B
JavaScript
let cachedConfig = null;
|
|
let expiresAt = 0;
|
|
|
|
function getPublicSystemConfigCache(now = Date.now()) {
|
|
if (!cachedConfig || expiresAt <= now) {
|
|
return null;
|
|
}
|
|
|
|
return cachedConfig;
|
|
}
|
|
|
|
function getStalePublicSystemConfigCache() {
|
|
return cachedConfig;
|
|
}
|
|
|
|
function setPublicSystemConfigCache(config, ttlMs, now = Date.now()) {
|
|
cachedConfig = config;
|
|
expiresAt = now + Math.max(Number(ttlMs) || 0, 0);
|
|
return cachedConfig;
|
|
}
|
|
|
|
function clearPublicSystemConfigCache() {
|
|
cachedConfig = null;
|
|
expiresAt = 0;
|
|
}
|
|
|
|
module.exports = {
|
|
clearPublicSystemConfigCache,
|
|
getPublicSystemConfigCache,
|
|
getStalePublicSystemConfigCache,
|
|
setPublicSystemConfigCache,
|
|
};
|