1
0
mirror of synced 2025-12-21 10:57:10 -05:00

Optimize rendering cache (#27917)

* Optimize rendering cache

* deleted the wrong return

* put it back

* oops. thanks eslint
This commit is contained in:
Peter Bengtsson
2022-05-23 14:32:05 -04:00
committed by GitHub
parent 8d4e1cda62
commit e53f40cfc6

View File

@@ -83,6 +83,11 @@ export default async function cacheFullRendering(req, res, next) {
} else {
const originalEndFunc = res.end.bind(res)
res.end = function (body) {
// Can end the response to the user now
originalEndFunc(body)
// After the response has been sent back to the user,
// take our time to store this in the cache.
if (body && res.statusCode === 200) {
// It's important to note that we only cache the HTML outputs.
// Why, because JSON outputs should be cached in the CDN.
@@ -100,7 +105,6 @@ export default async function cacheFullRendering(req, res, next) {
// If it's not HTML or JSON, it's probably an image (binary)
// or some plain text. Let's ignore all of those.
}
return originalEndFunc(body)
}
}