Add customizable cache for web instance (#193)
This commit is contained in:
@@ -70,7 +70,11 @@
|
|||||||
}
|
}
|
||||||
//Cache headers middleware
|
//Cache headers middleware
|
||||||
middlewares.push((req, res, next) => {
|
middlewares.push((req, res, next) => {
|
||||||
res.header("Cache-Control", cached ? `public, max-age=${Math.round(cached/1000)}` : "no-store, no-cache")
|
const maxage = Math.round(Number(req.query.cache))
|
||||||
|
if ((cached)||(maxage > 0))
|
||||||
|
res.header("Cache-Control", `public, max-age=${Math.round((maxage > 0 ? maxage : cached)/1000)}`)
|
||||||
|
else
|
||||||
|
res.header("Cache-Control", "no-store, no-cache")
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -195,8 +199,10 @@
|
|||||||
convert:["jpeg", "png", "json"].includes(q["config.output"]) ? q["config.output"] : null,
|
convert:["jpeg", "png", "json"].includes(q["config.output"]) ? q["config.output"] : null,
|
||||||
}, {Plugins, Templates})
|
}, {Plugins, Templates})
|
||||||
//Cache
|
//Cache
|
||||||
if ((!debug)&&(cached))
|
if ((!debug)&&(cached)) {
|
||||||
cache.put(login, {rendered, mime}, cached)
|
const maxage = Math.round(Number(req.query.cache))
|
||||||
|
cache.put(login, {rendered, mime}, maxage > 0 ? maxage : cached)
|
||||||
|
}
|
||||||
//Send response
|
//Send response
|
||||||
res.header("Content-Type", mime)
|
res.header("Content-Type", mime)
|
||||||
return res.send(rendered)
|
return res.send(rendered)
|
||||||
|
|||||||
Reference in New Issue
Block a user