0
votes

I'm working Symfony 2.6 HTTP cache, I'm following all the instructions in Symfony cook book here

But, why the response always X-Symfony-Cache: MISS. I try to modification AppModification.php erase array on privates header. the response header is X-Symfony-Cache:GET /page: fresh.

After I modified array, I got new problem, while I'm trying to login to my web I got error or message the page isn't working.

here my code before erase array private header:

protected function getOptions()
{
    return array(
        'debug'                  => true,
        'default_ttl'            => 60,
        'private_headers'        => array('Authorization', 'Cookie'),
        'allow_reload'           => false,
        'allow_revalidate'       => false,
        'stale_while_revalidate' => 2,
        'stale_if_error'         => 60,
    );
} 

Response Headers:

Cache-Control:private Connection:Keep-Alive Content-Type:text/html; charset=UTF-8 Date:Wed, 29 Jun 2016 03:37:56 GMT Keep-Alive:timeout=5, max=100 Server:Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.30 Transfer-Encoding:chunked X-Powered-By:PHP/5.5.30 X-Symfony-Cache:GET /page: stale, invalid

I try to erase array private header

protected function getOptions()
{
    return array(
        'debug'                  => true,
        'default_ttl'            => 60,
        'private_headers'        => array(),
        'allow_reload'           => false,
        'allow_revalidate'       => false,
        'stale_while_revalidate' => 2,
        'stale_if_error'         => 60,
    );
}

Response Headers:

Age:2 Cache-Control:public, s-maxage=62 Connection:Keep-Alive Content-Length:366990 Content-Type:text/html; charset=UTF-8 Date:Wed, 29 Jun 2016 03:41:56 GMT Keep-Alive:timeout=5, max=100 Server:Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.30 X-Content-Digest:en5ea0d5af1ee851007583987e8dfb3a8207874e303363f3d33c412b7f3fe6c12c X-Powered-By:PHP/5.5.30 X-Symfony-Cache:GET /page: stale, invalid, store

anyone can help me, to suggest to solve this problem? I have no idea anymore, and can't find in any Symfony documentation.

Here my controller:

public function showDetailsAction( $pageSlug,request $request)
{
    $productManager = $this->get('my.core.manager.product');
    $product = $productManager->findOneProduct();
    $options =  $cmsManager->getSlugType($pageSlug);

    $memcacheKey = 'prodrelated_'.$productNumber;
    if($this->get('memcache.default')->get($memcacheKey)){
        $result = $this->get('memcache.default')->get($memcacheKey);
    }else{
        $cloudSearchManager   = $this->get('my.core.manager.cloudsearch');
        $result = $cloudSearchManager->findRelatedProductBy($options);            
        $this->get('memcache.default')->set($memcacheKey, $result, 0, 300);
    }

    $view = $this
        ->view()
        ->setTemplate("MyBundle:Product:detail.html.twig")
        ->setData(array(
            'product'   => $product
        ));

    return $this->handleView($view);
}
1
Please show annotations of your /page action. - Ziumin
do you mean my controller? - karl
Yeah, just to check if you've added @Cache annotation or properly modified your Response object - Ziumin
I'm just add my controller code - karl
Try to add $response = $view->getResponse(); $response->setPublic(); $response->setSharedMaxAge(600); before return. - Ziumin

1 Answers

2
votes

The Symfony Cache layer acts like an intermediary HTTP cache, much like a reverse proxy like Varnish would.

This means that for a response to be cacheable, it needs to be public (any cache can store it) and not private (only the browser cache may store it). Additionally, an appropriate caching strategy must be used, like a max-age in the Cache-Control header or an Expires header.