From f79b0d8094ae8d6a0908d827944374d5979533aa Mon Sep 17 00:00:00 2001 From: biglyderv Date: Wed, 12 Feb 2025 00:58:44 -0500 Subject: [PATCH] add caching --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b785332..faa44f2 100644 --- a/index.js +++ b/index.js @@ -26,11 +26,19 @@ let settings = { arrayMax }; +let cache = {}; +let cacheDate = 0; + if (mode == 'cli') { main(settings); } else if (mode == 'site') { const app = e(); app.get('/top', async (req, res) => { + if ((new Date) - cacheDate < 1000*10) { + res.send(cache); + return; + } + let json = await fetch("https://nbg.dervland.net/api/followjson.php"); try { json = await json.json(); @@ -70,7 +78,10 @@ if (mode == 'cli') { dat2[d[0]] = d[1] * 100 + "%"; } - res.send(JSON.stringify(dat2)) + cache = JSON.stringify(dat2); + cacheDate = +(new Date); + + res.send(cache) }) app.listen(port);