Edge Side Includes and validation cache in Symfony 2

拟墨画扇 提交于 2019-12-06 03:17:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!