add caching
This commit is contained in:
parent
e29ac278f3
commit
f79b0d8094
1 changed files with 12 additions and 1 deletions
13
index.js
13
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);
|
||||
|
|
Loading…
Reference in a new issue