未验证 提交 72a461f9 编写于 作者: F Fabian Mastenbroek 提交者: GitHub

Do not cache 404 SSR responses (#10596)

This change updates the _ssr-caching_ to not cache the response when a
404 status code has been returned.
上级 9fdd344c
......@@ -10,9 +10,18 @@ const handle = app.getRequestHandler()
const ssrCache = cacheableResponse({
ttl: 1000 * 60 * 60, // 1hour
get: async ({ req, res, pagePath, queryParams }) => ({
data: await app.renderToHTML(req, res, pagePath, queryParams),
}),
get: async ({ req, res, pagePath, queryParams }) => {
const data = await app.renderToHTML(req, res, pagePath, queryParams)
// Add here custom logic for when you do not want to cache the page, for
// example when the page returns a 404 status code:
if (res.statusCode === 404) {
res.end(data)
return
}
return { data }
},
send: ({ data, res }) => res.send(data),
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册