add caching

This commit is contained in:
biglyderv 2025-02-12 00:58:44 -05:00
parent e29ac278f3
commit f79b0d8094
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5

View file

@ -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);