I'm playing with Symfony2 Reverse proxy and HTTP cache and I had a lot of read on the subject. However I'm getting stuck on how it works in my case.
Here is a use case.
GET /api/articles
returns something like:
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: application/json
Set-Cookie: PHPSESSID=12345; expires=Thu, 14-Nov-2013 14:50:35 GMT; path=/
age: 0
allow: GET, POST
cache-control: must-revalidate, no-cache, private
etag: "da4b6c4f1540a12a112936e58db06df8c95fd3c4"
vary: Accept,Accept-Encoding
x-content-digest: enbf30f962b06f99bd91843741537e112fbd3300c8
x-symfony-cache: GET /api/articles: miss, store
As you can see there the Cache-Control
header is marked as private along with no-cache & must-revalidate. However, I think I'm setting the Response
correctly:
$response = clone $view->getResponse();
$response
->setPublic()
->setEtag($etag)
->setSharedMaxAge(60)
->setVary(array('Accept'))
;
if ($response->isNotModified($this->getRequest())) {
return $response;
}
I set it to Public so it should work. You may have noticed the Set-Cookie
header, I dunno if it matters, but as long as I set the cache as public it shouldn't, isn't it?
Now, if I GET /api/articles
with an If-None-Match: {etag}
I get a 304 which is correct, but the Cache-Control
header is the same.
Note that if I disable the Reverse Proxy, the Cache-Control is correct and showing me:
Cache-Control: public, s-maxage=60
which is what I except.