Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedMar 17, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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. |
mpdude commentedMar 17, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Regarding the method, it could be private as well. Regarding changing behavior, every bug fix is a BC break 🙈 |
Nek- commentedMar 17, 2017
|
mpdude commentedMar 17, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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: |
xabbuh commentedMar 17, 2017
I am not sure if I get the root issue. What exactly is the point of caching a response with |
mpdude commentedMar 17, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It may be expensive for your Controller to generate the complete response, but an If-Modified-Since check may be cheap. By sending |
mpdude commentedMar 17, 2017
Why's the test failing on PHP 7 😒 ? |
xabbuh commentedMar 17, 2017
You would have to tell the HttpKernel component to make use of version |
mpdude commentedMar 18, 2017
I missed that in order to make revalidation possible, the response needs an If that is present, |
mpdude commentedMar 18, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
In case you'd be interested, here's a test to safeguard this: namespaceSymfony\Component\HttpKernel\Tests\HttpCache;class HttpCacheTest ... publicfunctiontestServesResponseWhileFreshAndRevalidatesWithLastModifiedInformation() {$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'); } |
fabpot commentedMar 20, 2017
@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
HttpCachehandling responses withs-maxage=0.Though I cannot find a place in the RFCs that explicitly states it, I have always interpreted a
max-ageof 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
HttpCacheto keep the entire response but revalidate it every time using anETagorLast-Modifiedinformation.