I'm working currently on REST API. I wanted to check if HTTP cache is working fine, but unfortunatelly I doesn't work at all. No matter what I do, it always return HTTP code 200 while it should return 304 from what I know.
Here is my PHP code:
public function getList()
{
$this->addHeaders(array(
'Cache-Control' => 'public, must-revalidate, max-age=120',
'eTag' => 'xyz123',
));
$array = array(
'foo' => 'bar',
'nested' => array(
'lorem' => 'ipsum',
'dolor' => 'sit amet'
)
);
$this->addHeader('Content-Length', strlen(json_encode($array, true)));
return new JsonModel($array);
}
Response/Request
ETag doesn't change, so requests except first one should be served from cache. Am I wrong?
I was following these 2 articles:
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching
- https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en
I also checked with weak validator- Last-Modified but I got same problem. Browser sends correct header in Request, but I still get 200 in response
