问题描述
是否可以在带有 Symfony 2 的 ESI 中使用验证缓存?
Is it possible to use validation cache in an ESI with Symfony 2 ?
如果您查看 HttpFoundation Response 类,你可以看到 isNotModified 是如何工作的:
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;
}
问题是ESI $request->headers->get('If-Modified-Since');并且 $request->getEtags() 在 ESI 中不返回任何内容......所以缓存永远不会新鲜!
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 !
那么你有解决 $request 的方法吗?
So do you have a solution for the $request ?
如果验证 HTTP 缓存无法在 ESI 中工作,是否还有其他方法可以缓存部分内容?
If validation HTTP cache can't work in an ESI, is there another way to cache the partial ?
谢谢!
推荐答案
我还没有在 Symfony2 中使用 ESI(目前) - 但 Symfony2 文档文章 使用 Edge Side Includes 似乎表明这是一个非常简单的过程.
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.
这篇关于Symfony 2 中的 Edge Side Includes 和验证缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!