Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edge Side Includes and validation cache in Symfony 2

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 !

like image 609
Sybio Avatar asked Nov 14 '22 09:11

Sybio


1 Answers

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.

like image 170
leek Avatar answered Dec 21 '22 17:12

leek