1
0
mirror of synced 2025-12-23 21:07:12 -05:00

Merge branch 'main' of https://github.com/github/docs-internal into hidden-docs-alt

This commit is contained in:
Sarah Schneider
2020-10-23 10:28:52 -04:00
32 changed files with 264 additions and 123 deletions

View File

@@ -6,8 +6,21 @@ const layouts = require('../lib/layouts')
const getMiniTocItems = require('../lib/get-mini-toc-items')
const Page = require('../lib/page')
// We've got lots of memory, let's use it
// We can eventually throw this into redis
const pageCache = {}
module.exports = async function renderPage (req, res, next) {
const page = req.context.page
const originalUrl = req.originalUrl
// Serve from the cache if possible
if (!process.env.CI) {
if (req.method === 'GET' && pageCache[originalUrl]) {
console.log(`Serving from cached version of ${originalUrl}`)
return res.send(pageCache[originalUrl])
}
}
// render a 404 page
if (!page) {
@@ -74,5 +87,13 @@ module.exports = async function renderPage (req, res, next) {
const output = await liquid.parseAndRender(layout, context)
res.send(output)
// Save output to cache for the next time around
if (!process.env.CI) {
if (req.method === 'GET') {
pageCache[originalUrl] = output
}
}
// send response
return res.send(output)
}