lamassu-server/lib/middlewares/settingsCache.js
Cesar 558317e9f3 Feat: implement per operator settings cache
Fix: fix linter-found issues

Chore: move findOperatorId to own middleware file

Chore: delete old routes.js file and rename new-routes.js to routes.js

Fix: PR fixes
2021-03-19 14:04:31 +00:00

26 lines
770 B
JavaScript

const _ = require('lodash/fp')
const state = require('./state')
const getTimestamp = (operatorId) => state.settingsCache[operatorId] ? state.settingsCache[operatorId].timestamp : null
const getCache = (operatorId) => state.settingsCache[operatorId] ? state.settingsCache[operatorId].cache : null
const setTimestamp = (operatorId, newTimestamp) => {
state.settingsCache = _.set([operatorId, 'timestamp'], newTimestamp, state.settingsCache)
}
const setCache = (operatorId, newCache) => {
state.settingsCache = _.set([operatorId, 'cache'], newCache, state.settingsCache)
}
const clear = (operatorId) => {
state.settingsCache = _.set([operatorId], null, state.settingsCache)
}
module.exports = {
getTimestamp,
getCache,
setTimestamp,
setCache,
clear
}