-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add new isExpirable() method and consider s-maxage=0 cacheable #22035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introducing a new method is a new feature, changing a behavior a "bc break". This PR does both but is classified as bug fix. Triggers a red flag to me, needs to be well discussed/justified. |
Regarding the method, it could be private as well. Regarding changing behavior, every bug fix is a BC break 🙈 |
|
You're right, I missed that... But do you agree that a it would be fine to cache a response with In When looked up in the cache, here's the check whether the response is fresh enough: |
I am not sure if I get the root issue. What exactly is the point of caching a response with |
It may be expensive for your Controller to generate the complete response, but an If-Modified-Since check may be cheap. By sending |
Why's the test failing on PHP 7 😒 ? |
You would have to tell the HttpKernel component to make use of version |
I missed that in order to make revalidation possible, the response needs an If that is present, |
In case you'd be interested, here's a test to safeguard this: namespace Symfony\Component\HttpKernel\Tests\HttpCache;
class HttpCacheTest ...
public function testServesResponseWhileFreshAndRevalidatesWithLastModifiedInformation()
{
$time = \DateTime::createFromFormat('U', time());
$this->setNextResponse(200, [], 'Hello World', function (Request $request, Response $response) use ($time) {
$response->setSharedMaxAge(10);
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
});
// prime the cache
$this->request('GET', '/');
// next request before s-maxage has expired: Serve from cache without hitting the backend
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertTraceContains('fresh');
sleep(15); // expire the cache
$this->setNextResponse(304, [], '', function (Request $request, Response $response) use ($time) {
$this->assertEquals($time->format(DATE_RFC2822), $request->headers->get('IF_MODIFIED_SINCE'));
});
$this->request('GET', '/');
$this->assertHttpKernelIsCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertTraceContains('stale');
$this->assertTraceContains('valid');
} |
@mpdude Can you submit a PR with just this test then? |
…xpired TTL (mpdude) This PR was squashed before being merged into the 2.7 branch (closes #22099). Discussion ---------- HttpCache: New test for revalidating responses with an expired TTL | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | See #22035, in particular [this and the following comments](#22035 (comment)). Commits ------- 067ab52 HttpCache: New test for revalidating responses with an expired TTL
…xpired TTL (mpdude) This PR was squashed before being merged into the 2.7 branch (closes #22099). Discussion ---------- HttpCache: New test for revalidating responses with an expired TTL | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | See #22035, in particular [this and the following comments](symfony/symfony#22035 (comment)). Commits ------- 067ab52 HttpCache: New test for revalidating responses with an expired TTL
As in #22033, I am trying to find an issue with the
HttpCache
handling responses withs-maxage=0
.Though I cannot find a place in the RFCs that explicitly states it, I have always interpreted a
max-age
of zero to mean "you may cache this, but you must revalidate it before it is used the next time".This is useful for example when using Symfony's
HttpCache
to keep the entire response but revalidate it every time using anETag
orLast-Modified
information.