removed cache options

This commit is contained in:
Daniel Sommer 2022-03-24 23:35:51 +01:00
parent 72edb1a159
commit c5b5844233
2 changed files with 3 additions and 43 deletions

View file

@ -1,17 +1,13 @@
{ {
"server": { "server": {
"listen": "0.0.0.0", "listen": "0.0.0.0",
"port": 3001 "port": 3000
}, },
"requests": { "requests": {
"timeout": 5000 "timeout": 5000
}, },
"cache": {
"active": true,
"lifetime": 0
},
"systemd": [ "systemd": [
"docker" "jack-capture"
], ],
"log": { "log": {
"level": "debug", "level": "debug",
@ -28,7 +24,7 @@
}, },
"blinky": { "blinky": {
"enabled": true, "enabled": true,
"host": "192.168.1.70", "host": "192.168.1.31",
"port": 3000, "port": 3000,
"colors": { "colors": {
"BigMuffPi": { "BigMuffPi": {

View file

@ -2,31 +2,11 @@ const logger = require('./logger.js');
const constants = require('./constants.js'); const constants = require('./constants.js');
const timeDiff = require('./util.js').timeDiff; const timeDiff = require('./util.js').timeDiff;
let active;
let lifetime;
let modep; let modep;
const cache = new Map(); const cache = new Map();
function isActive() {
if (active === undefined) {
active = global.config.cache.active;
}
return active;
}
function getLifetime() {
if (lifetime === undefined) {
lifetime = global.config.cache.lifetime * 60000
}
return lifetime;
}
async function fill() { async function fill() {
if (!isActive) {
return;
}
const timestamp = new Date(); const timestamp = new Date();
logger.debug('filling cache...'); logger.debug('filling cache...');
clear(); clear();
@ -50,25 +30,11 @@ function clear() {
cache.clear(); cache.clear();
} }
function validLifetime(timestamp) {
if (timestamp === undefined) {
return false;
}
if (lifetime === 0) {
return true;
}
return (new Date().getTime() - timestamp) <= lifetime;
}
function getValue(key) { function getValue(key) {
let value = cache.get(key); let value = cache.get(key);
if (value === undefined) { if (value === undefined) {
return undefined; return undefined;
} }
if (!validLifetime(value.timestamp)) {
resetValue(key)
return undefined;
}
return cache.get(key).data; return cache.get(key).data;
} }
@ -189,8 +155,6 @@ function clearBypassedPedals() {
} }
module.exports = { module.exports = {
isActive,
getLifetime,
fill, fill,
clear, clear,
getBanks, getBanks,