the
This commit is contained in:
parent
fb72b4e357
commit
40ed4d2e27
2 changed files with 8 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
node_modules
|
||||
.idea
|
9
main.js
9
main.js
|
@ -17,7 +17,7 @@ app.get('/', async (req, res) => {
|
|||
const url = req.query.url;
|
||||
|
||||
if (!url) {
|
||||
res.status(400).send("nop");
|
||||
res.status(400).contentType("text/plain").send("nop");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ app.get('/', async (req, res) => {
|
|||
|
||||
if (row) {
|
||||
const currentTime = getCurrentUnixTimestamp();
|
||||
const twoHoursInSeconds = 10;
|
||||
const twoHoursInSeconds = 7200;
|
||||
|
||||
if (currentTime - row.time > twoHoursInSeconds) {
|
||||
db.run(`DELETE FROM cache WHERE id = ?`, [url], async (err) => {
|
||||
|
@ -51,6 +51,7 @@ app.get('/', async (req, res) => {
|
|||
return;
|
||||
}
|
||||
res.contentType("application/json");
|
||||
res.header("cache", "stale - invalidated");
|
||||
res.send(resp)
|
||||
console.log("old response (entry readded)");
|
||||
});
|
||||
|
@ -58,7 +59,7 @@ app.get('/', async (req, res) => {
|
|||
insertStmt.finalize();
|
||||
});
|
||||
} else {
|
||||
console.log("cache valid")
|
||||
res.header("cache", "fresh");
|
||||
res.contentType("application/json");
|
||||
res.send(row.response);
|
||||
}
|
||||
|
@ -73,7 +74,9 @@ app.get('/', async (req, res) => {
|
|||
return;
|
||||
}
|
||||
res.contentType("application/json");
|
||||
res.header("cache", "wasnt");
|
||||
res.send(resp)
|
||||
|
||||
console.log("New entry added");
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue