File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -507,13 +507,19 @@ public function getCharset()
507
507
}
508
508
509
509
/**
510
- * Returns true if the response is worth caching under any circumstance .
510
+ * Returns true if the response may safely be kept in a shared (surrogate) cache .
511
511
*
512
512
* Responses marked "private" with an explicit Cache-Control directive are
513
513
* considered uncacheable.
514
514
*
515
515
* Responses with neither a freshness lifetime (Expires, max-age) nor cache
516
- * validator (Last-Modified, ETag) are considered uncacheable.
516
+ * validator (Last-Modified, ETag) are considered uncacheable because there is
517
+ * no way to tell when or how to remove them from the cache.
518
+ *
519
+ * Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
520
+ * for example "status codes that are defined as cacheable by default [...]
521
+ * can be reused by a cache with heuristic expiration unless otherwise indicated"
522
+ * (https://tools.ietf.org/html/rfc7231#section-6.1)
517
523
*
518
524
* @return bool true if the response is worth caching, false otherwise
519
525
*/
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ public function update(Response $response)
72
72
$ response ->setLastModified (null );
73
73
}
74
74
75
- if (!$ response ->isFresh ()) {
75
+ if (!$ response ->isFresh () || ! $ response -> isCacheable () ) {
76
76
$ this ->cacheable = false ;
77
77
}
78
78
Original file line number Diff line number Diff line change @@ -175,8 +175,26 @@ public function testEmbeddingPrivateResponseMakesMainResponsePrivate()
175
175
$ cacheStrategy ->update ($ masterResponse );
176
176
177
177
$ this ->assertTrue ($ masterResponse ->headers ->hasCacheControlDirective ('private ' ));
178
- // Not sure if we should pass "max-age: 60" in this case, as long as the response is private and
179
- // that's the more conservative of both the master and embedded response...?
178
+ $ this ->assertFalse ($ masterResponse ->headers ->hasCacheControlDirective ('public ' ));
179
+ }
180
+
181
+ public function testEmbeddingPublicResponseDoesNotMakeMainResponsePublic ()
182
+ {
183
+ $ cacheStrategy = new ResponseCacheStrategy ();
184
+
185
+ $ masterResponse = new Response ();
186
+ $ masterResponse ->setPrivate (); // this is the default, but let's be explicit
187
+ $ masterResponse ->setMaxAge (100 );
188
+
189
+ $ embeddedResponse = new Response ();
190
+ $ embeddedResponse ->setPublic ();
191
+ $ embeddedResponse ->setSharedMaxAge (100 );
192
+
193
+ $ cacheStrategy ->add ($ embeddedResponse );
194
+ $ cacheStrategy ->update ($ masterResponse );
195
+
196
+ $ this ->assertTrue ($ masterResponse ->headers ->hasCacheControlDirective ('private ' ));
197
+ $ this ->assertFalse ($ masterResponse ->headers ->hasCacheControlDirective ('public ' ));
180
198
}
181
199
182
200
public function testResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndValidation ()
You can’t perform that action at this time.
0 commit comments