Symfony2: ESI setMaxAge Cache

本小妞迷上赌 提交于 2019-12-06 09:25:44

In Symfony2 there's a few things you need to do in order to activate esi caching.

1) In app/config/config.yml make sure you activated esi, with a fragments path.

framework:
    esi: { enabled: true }
    fragments: { path: /_proxy }

2) Wrap the kernel with the AppCache object

// web/app.php
$kernel = new AppCache($kernel); 

3) Set up the AppCache configuration

// app/AppCache.php
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;

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

About your issue if it is caching your response and the only problem is that it's reloading every time you refresh the page. make sure the configuration allow_reload property is set to false.

You can read more about it here: http://symfony.com/doc/current/book/http_cache.html

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