是否可以在ESI中使用Symfony 2验证缓存?
如果查看HttpFoundation Response课程,您可以看到isNotModified如何运作:
/**
* 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;
}
问题是ESI $ request-> headers-> get('If-Modified-Since');和$ request-> getEtags()在ESI中没有返回任何内容......所以缓存永远不会新鲜!
那么你有一个$ request的解决方案吗?
如果验证HTTP缓存在ESI中不起作用,是否有另一种缓存部分的方法?
谢谢!