diff --git a/core/modules/page_cache/src/StackMiddleware/PageCache.php b/core/modules/page_cache/src/StackMiddleware/PageCache.php index f25c685..a2792a3 100644 --- a/core/modules/page_cache/src/StackMiddleware/PageCache.php +++ b/core/modules/page_cache/src/StackMiddleware/PageCache.php @@ -312,6 +312,14 @@ protected function get(Request $request, $allow_invalid = FALSE) { */ protected function set(Request $request, Response $response, $expire, array $tags) { $cid = $this->getCacheId($request); + + // Do not store 404 responses in the cache for longer than an hour. + if ($response->getStatusCode() == $response::HTTP_NOT_FOUND) { + $max_age = $response->getMaxAge(); + // Cache for an hour or the maximum age, which ever is the greater. + $expire = REQUEST_TIME + min($max_age, 3600); + } + $this->cache->set($cid, $response, $expire, $tags); }