Fix LDB Cache, so when data is missing, nothing is cached

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2024-04-29 11:16:40 +01:00
parent afa4ad7915
commit 8fa0cf775f
2 changed files with 10 additions and 3 deletions

View File

@ -9,7 +9,7 @@ async function getTrain(req, res, next) {
err.status = 401; err.status = 401;
throw err; throw err;
} }
setCache(res, "private", 180) setCache(res, "private", 240)
let type = req.params.searchType; let type = req.params.searchType;
let id = req.params.id; let id = req.params.id;
try { try {
@ -45,8 +45,14 @@ async function getStation(req, res, next) {
err.status = 401; err.status = 401;
return next(err); return next(err);
} }
setCache(res, "public", 120) const data = await ldb.get(id, true);
res.json(await ldb.get(id, true)); // Only cache if data is present
if (data.data) {
setCache(res, "public", 120);
} else {
setCache(res, "no-store", 120);
}
res.json(data);
} else { } else {
setCache(res, "public", 240) setCache(res, "public", 240)
res.json(await ldb.get(id, false)); res.json(await ldb.get(id, false));

View File

@ -18,6 +18,7 @@ async function getReasonCode(req, res, next) {
} catch (err) { } catch (err) {
console.error("ERROR", err.message); console.error("ERROR", err.message);
err.status = 500; err.status = 500;
setCache(res, "no-store", 5)
next(err); next(err);
} }
} }