const settingsDao = require('../dao/settings.dao')

let cache = null
let cacheTime = 0
const TTL = 60000 // 1 minute

async function getSettings() {
  if (cache && Date.now() - cacheTime < TTL) return cache
  cache = await settingsDao.getAll()
  cacheTime = Date.now()
  return cache
}

function invalidateCache() {
  cache = null
  cacheTime = 0
}

module.exports = { getSettings, invalidateCache }
