@@ -37,8 +37,8 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
37
37
private int $ embeddedResponses = 0 ;
38
38
private bool $ isNotCacheableResponseEmbedded = false ;
39
39
private int $ age = 0 ;
40
- private array $ lastModified = null ;
41
- private $ flagDirectives = [
40
+ private \ DateTimeInterface | null | false $ lastModified = null ;
41
+ private array $ flagDirectives = [
42
42
'no-cache ' => null ,
43
43
'no-store ' => null ,
44
44
'no-transform ' => null ,
@@ -92,8 +92,8 @@ public function add(Response $response)
92
92
$ expires = null !== $ expires ? (int ) $ expires ->format ('U ' ) - (int ) $ response ->getDate ()->format ('U ' ) : null ;
93
93
$ this ->storeRelativeAgeDirective ('expires ' , $ expires >= 0 ? $ expires : null , 0 , $ isHeuristicallyCacheable );
94
94
95
- $ lastModified = $ response ->getLastModified ();
96
95
if (false !== $ this ->lastModified ) {
96
+ $ lastModified = $ response ->getLastModified ();
97
97
$ this ->lastModified = $ lastModified ? max ($ this ->lastModified , $ lastModified ) : false ;
98
98
}
99
99
}
@@ -116,7 +116,7 @@ public function update(Response $response)
116
116
$ response ->headers ->set ('Age ' , $ this ->age );
117
117
118
118
if ($ this ->isNotCacheableResponseEmbedded ) {
119
- $ response ->setLastModified (null );
119
+ $ response ->setLastModified ();
120
120
121
121
if ($ this ->flagDirectives ['no-store ' ]) {
122
122
$ response ->headers ->set ('Cache-Control ' , 'no-cache, no-store, must-revalidate ' );
@@ -169,17 +169,14 @@ private function willMakeFinalResponseUncacheable(Response $response): bool
169
169
// RFC2616: A response received with a status code of 200, 203, 300, 301 or 410
170
170
// MAY be stored by a cache […] unless a cache-control directive prohibits caching.
171
171
if ($ response ->headers ->hasCacheControlDirective ('no-cache ' )
172
- || $ response ->headers ->getCacheControlDirective ('no-store ' )
172
+ || $ response ->headers ->hasCacheControlDirective ('no-store ' )
173
173
) {
174
174
return true ;
175
175
}
176
176
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
178
178
// 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 ])) {
183
180
return false ;
184
181
}
185
182
0 commit comments