问题
Is it possible to use validation cache in an ESI with Symfony 2 ?
If you look the HttpFoundation Response class, you can see how isNotModified works:
/**
* Determines if the Response validators (ETag, Last-Modified) match
* a conditional value specified in the Request.
*
* If the Response is not modified, it sets the status code to 304 and
* removes the actual content by calling the setNotModified() method.
*
* @param Request $request A Request instance
*
* @return Boolean true if the Response validators match the Request, false otherwise
*
* @api
*/
public function isNotModified(Request $request)
{
$lastModified = $request->headers->get('If-Modified-Since');
$notModified = false;
if ($etags = $request->getEtags()) {
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
} elseif ($lastModified) {
$notModified = $lastModified == $this->headers->get('Last-Modified');
}
if ($notModified) {
$this->setNotModified();
}
return $notModified;
}
The problem is that ESI $request->headers->get('If-Modified-Since'); and $request->getEtags() return nothing in an ESI... so the cache is never fresh !
So do you have a solution for the $request ?
If validation HTTP cache can't work in an ESI, is there another way to cache the partial ?
Thank you !
回答1:
I haven't used ESI with Symfony2 (yet) - but the Symfony2 documentation article Using Edge Side Includes seems to suggest that it is a pretty straightforward process.
来源:https://stackoverflow.com/questions/9633151/edge-side-includes-and-validation-cache-in-symfony-2