From 2c8b07a9bbe889c76552723d1d8363c46d7f6900 Mon Sep 17 00:00:00 2001 From: Thomas Boutell Date: Tue, 3 May 2022 18:57:20 -0400 Subject: [PATCH] disable cache for now --- lib/server.js | 70 +++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/lib/server.js b/lib/server.js index 84b3813..0a27bf9 100644 --- a/lib/server.js +++ b/lib/server.js @@ -8,7 +8,9 @@ const renderer = require(appPath).default; const pageSize = 20; const versionFile = `${__dirname}/../version.txt`; const version = fs.existsSync(versionFile) ? fs.readFileSync(versionFile, 'utf8') : '0'; -const cache = {}; + +// Disabled for now because it causes confusion when we update the data +// const cache = {}; module.exports = async function({ plants, nurseries }) { const port = process.env.PORT || 3000; @@ -20,10 +22,6 @@ module.exports = async function({ plants, nurseries }) { app.use(express.static(publicDir)); app.use('/images', express.static(`${__dirname}/../images`)); app.get('/api/v1/plants', async (req, res) => { - const data = getCache(req); - if (data) { - return res.send(data); - } try { const fetchResults = req.query.results !== '0'; const fetchTotal = req.query.total !== '0'; @@ -323,7 +321,7 @@ module.exports = async function({ plants, nurseries }) { response.counts[filter.name] = Object.fromEntries(Object.entries(counts).filter((value, count) => !filter.ignore.includes(value))); } } - setCache(req, response); + // setCache(req, response); return res.send(response); } catch (e) { console.error('error:', e); @@ -381,35 +379,35 @@ module.exports = async function({ plants, nurseries }) { return app; }; -function hashKey(req) { - return JSON.stringify(req.query); -} +// function hashKey(req) { +// return JSON.stringify(req.query); +// } -function getCache(req) { - const key = hashKey(req); - if (cache[key]) { - cache[key].last = Date.now(); - return cache[key].data; - } -} +// function getCache(req) { +// const key = hashKey(req); +// if (cache[key]) { +// cache[key].last = Date.now(); +// return cache[key].data; +// } +// } -function setCache(req, data) { - cache[hashKey(req)] = { - last: Date.now(), - data - }; - if (Object.keys(cache).length > 100) { - const oldest = Object.entries(cache, (a, [key, value]) => { - if ((!a) || (value.last < a.last)) { - return [key, value]; - } - }, null); - if (oldest) { - // console.log('Deleting:', oldest[0]); - delete cache[oldest[0]]; - } - } - // Object.keys(cache).map(key => { - // console.log(`${key} ${cache[key].last}`); - // }); -} +// function setCache(req, data) { +// cache[hashKey(req)] = { +// last: Date.now(), +// data +// }; +// if (Object.keys(cache).length > 100) { +// const oldest = Object.entries(cache, (a, [key, value]) => { +// if ((!a) || (value.last < a.last)) { +// return [key, value]; +// } +// }, null); +// if (oldest) { +// // console.log('Deleting:', oldest[0]); +// delete cache[oldest[0]]; +// } +// } +// // Object.keys(cache).map(key => { +// // console.log(`${key} ${cache[key].last}`); +// // }); +// }