@@ -37,8 +37,8 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
3737 private int $ embeddedResponses = 0 ;
3838 private bool $ isNotCacheableResponseEmbedded = false ;
3939 private int $ age = 0 ;
40- private array $ lastModified = null ;
41- private $ flagDirectives = [
40+ private \ DateTimeInterface | null | false $ lastModified = null ;
41+ private array $ flagDirectives = [
4242 'no-cache ' => null ,
4343 'no-store ' => null ,
4444 'no-transform ' => null ,
@@ -92,8 +92,8 @@ public function add(Response $response)
9292 $ expires = null !== $ expires ? (int ) $ expires ->format ('U ' ) - (int ) $ response ->getDate ()->format ('U ' ) : null ;
9393 $ this ->storeRelativeAgeDirective ('expires ' , $ expires >= 0 ? $ expires : null , 0 , $ isHeuristicallyCacheable );
9494
95- $ lastModified = $ response ->getLastModified ();
9695 if (false !== $ this ->lastModified ) {
96+ $ lastModified = $ response ->getLastModified ();
9797 $ this ->lastModified = $ lastModified ? max ($ this ->lastModified , $ lastModified ) : false ;
9898 }
9999 }
@@ -116,7 +116,7 @@ public function update(Response $response)
116116 $ response ->headers ->set ('Age ' , $ this ->age );
117117
118118 if ($ this ->isNotCacheableResponseEmbedded ) {
119- $ response ->setLastModified (null );
119+ $ response ->setLastModified ();
120120
121121 if ($ this ->flagDirectives ['no-store ' ]) {
122122 $ response ->headers ->set ('Cache-Control ' , 'no-cache, no-store, must-revalidate ' );
@@ -169,17 +169,14 @@ private function willMakeFinalResponseUncacheable(Response $response): bool
169169 // RFC2616: A response received with a status code of 200, 203, 300, 301 or 410
170170 // MAY be stored by a cache […] unless a cache-control directive prohibits caching.
171171 if ($ response ->headers ->hasCacheControlDirective ('no-cache ' )
172- || $ response ->headers ->getCacheControlDirective ('no-store ' )
172+ || $ response ->headers ->hasCacheControlDirective ('no-store ' )
173173 ) {
174174 return true ;
175175 }
176176
177- // Last-Modified and Etag headers cannot be merged, they render the response uncacheable
177+ // Etag headers cannot be merged, they render the response uncacheable
178178 // by default (except if the response also has max-age etc.).
179- if (\in_array ($ response ->getStatusCode (), [200 , 203 , 300 , 301 , 410 ])
180- && null === $ response ->getLastModified ()
181- && null === $ response ->getEtag ()
182- ) {
179+ if (null === $ response ->getEtag () && \in_array ($ response ->getStatusCode (), [200 , 203 , 300 , 301 , 410 ])) {
183180 return false ;
184181 }
185182
0 commit comments