【问题标题】:Edge Side Includes and validation cache in Symfony 2Symfony 2 中的 Edge Side Includes 和验证缓存
【发布时间】:2012-03-09 11:16:51
【问题描述】:

是否可以在带有 Symfony 2 的 ESI 中使用验证缓存?

如果你查看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 中工作,是否有其他方法可以缓存部分内容?

谢谢!

【问题讨论】:

    标签: symfony http-caching esi


    【解决方案1】:

    我还没有在 Symfony2 中使用 ESI - 但 Symfony2 文档文章 Using Edge Side Includes 似乎表明这是一个非常简单的过程。

    【讨论】:

    • 是的,使用过期缓存,这真的很简单,而且很有效!但是在使用验证缓存时似乎不起作用...所以我尝试调试它似乎不可能...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 2012-10-30
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多