From 389d421a3da67c0894bb8b79449e3e0204775974 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 22 Jul 2024 16:16:14 +0200 Subject: [PATCH] Only call store when response still is cacheable --- src/SymfonyCache/EventDispatchingHttpCache.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SymfonyCache/EventDispatchingHttpCache.php b/src/SymfonyCache/EventDispatchingHttpCache.php index c531c421..9df3f5ae 100644 --- a/src/SymfonyCache/EventDispatchingHttpCache.php +++ b/src/SymfonyCache/EventDispatchingHttpCache.php @@ -109,7 +109,11 @@ protected function store(Request $request, Response $response) { $response = $this->dispatch(Events::PRE_STORE, $request, $response); - parent::store($request, $response); + // CustomTtlListener or other Listener or Subscribers might have set a non-cacheable response so we need revalidate this + // So store is only called when cacheable like Symfony core would do: https://github.com/symfony/symfony/blob/v7.1.2/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php#L409 + if ($response->isCacheable()) { + parent::store($request, $response); + } } /**