Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09bcbc7

Browse files
committed
Embedding a response that combines expiration and validation, that should not defeat expiration on the combined response
1 parent551e5ba commit09bcbc7

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

‎src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
3939
*/
4040
publicfunctionadd(Response$response)
4141
{
42-
if ($response->isValidateable() || !$response->isCacheable()) {
42+
if (!$response->isFresh() || !$response->isCacheable()) {
4343
$this->cacheable =false;
4444
}else {
4545
$maxAge =$response->getMaxAge();
@@ -70,6 +70,9 @@ public function update(Response $response)
7070
if ($response->isValidateable()) {
7171
$response->setEtag(null);
7272
$response->setLastModified(null);
73+
}
74+
75+
if (!$response->isFresh()) {
7376
$this->cacheable =false;
7477
}
7578

‎src/Symfony/Component/HttpKernel/Tests/HttpCache/ResponseCacheStrategyTest.php‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,45 @@ public function testEmbeddingPrivateResponseMakesMainResponsePrivate()
178178
// Not sure if we should pass "max-age: 60" in this case, as long as the response is private and
179179
// that's the more conservative of both the master and embedded response...?
180180
}
181+
182+
publicfunctiontestResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndValidation()
183+
{
184+
/* When "expiration wins over validation" (https://symfony.com/doc/current/http_cache/validation.html)
185+
* and both the main and embedded response provide s-maxage, then the more restricting value of both
186+
* should be fine, regardless of whether the embedded response can be validated later on or must be
187+
* completely regenerated.
188+
*/
189+
$cacheStrategy =newResponseCacheStrategy();
190+
191+
$masterResponse =newResponse();
192+
$masterResponse->setSharedMaxAge(3600);
193+
194+
$embeddedResponse =newResponse();
195+
$embeddedResponse->setSharedMaxAge(60);
196+
$embeddedResponse->setEtag('foo');
197+
198+
$cacheStrategy->add($embeddedResponse);
199+
$cacheStrategy->update($masterResponse);
200+
201+
$this->assertSame('60',$masterResponse->headers->getCacheControlDirective('s-maxage'));
202+
}
203+
204+
publicfunctiontestResponseIsExpirableButNotValidateableWhenMasterResponseCombinesExpirationAndValidation()
205+
{
206+
$cacheStrategy =newResponseCacheStrategy();
207+
208+
$masterResponse =newResponse();
209+
$masterResponse->setSharedMaxAge(3600);
210+
$masterResponse->setEtag('foo');
211+
$masterResponse->setLastModified(new \DateTime());
212+
213+
$embeddedResponse =newResponse();
214+
$embeddedResponse->setSharedMaxAge(60);
215+
216+
$cacheStrategy->add($embeddedResponse);
217+
$cacheStrategy->update($masterResponse);
218+
219+
$this->assertSame('60',$masterResponse->headers->getCacheControlDirective('s-maxage'));
220+
$this->assertFalse($masterResponse->isValidateable());
221+
}
181222
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp