Php Symfony 2 ESI缓存
我有一个在我的所有页面中调用的操作(仅针对登录用户),该操作从我的twitter帐户检索最近的推文 API访问受限,因此我希望此操作的结果在缓存中保留10分钟Php Symfony 2 ESI缓存,php,symfony,caching,esi,Php,Symfony,Caching,Esi,我有一个在我的所有页面中调用的操作(仅针对登录用户),该操作从我的twitter帐户检索最近的推文 API访问受限,因此我希望此操作的结果在缓存中保留10分钟 public function socialAction(){ $consumerKey = $this->container->getParameter('consumer_key'); $consumerSecret = $this->container->getParameter('consum
public function socialAction(){
$consumerKey = $this->container->getParameter('consumer_key');
$consumerSecret = $this->container->getParameter('consumer_secret');
$accessToken = $this->container->getParameter('access_token');
$accessTokenSecret = $this->container->getParameter('access_token_secret');
// on appel l'API
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$screen_name = "blabla";
$tweets = $tweet->get('statuses/user_timeline', [
'screen_name' => $screen_name,
'exclude_replies' => true,
'count' => 50
]);
$tweets = array_splice($tweets, 0, 5);
$response = $this->render('GestionJeuBundle:Default:social.html.twig', array("tweets" => $tweets));
$response->setPublic();
$response->setSharedMaxAge(600);
return $response;
}
要启用我所做的缓存以下变化
app/config/config.yml
framework:
esi: { enabled: true }
fragments: { path: /_proxy }
及
换成
{{render_esi(controller("GestionJeuBundle:Default:social")) }}
解决我的问题
Hexune就我上周的实验而言,值得注意的是,如果您在Symfony中使用调试环境,Varnish总是将您的请求传递到后端。就我上周的实验而言,值得注意的是,如果您在Symfony中使用调试环境,Varnish总是将您的请求传递到后端。我正在使用
{{render(controller("GestionJeuBundle:Default:social")) }}
{{render(controller("GestionJeuBundle:Default:social")) }}
换成
{{render_esi(controller("GestionJeuBundle:Default:social")) }}
解决我的问题我正在用
{{render(controller("GestionJeuBundle:Default:social")) }}
{{render(controller("GestionJeuBundle:Default:social")) }}
换成
{{render_esi(controller("GestionJeuBundle:Default:social")) }}
解决我的问题您好,谢谢您的回答,但不幸的是,它在生产环境中的作用完全相同后端返回给代理的头是什么?我的头似乎有很好的价值。我的操作的响应头有以下内容:(cache-control=>public,s-maxage=600,x-debug-token=>1df192)我不确定请求头是否必须与cache.PS有关。不要忘记,除非指定了其他配置,否则通过客户端/后端发送cookie将完全禁用缓存。抱歉,我不知道什么是VCL(搜索后的Varnish配置语言),但我不知道如何找到它。同一操作的我的请求头在请求头中有一个cookie部分(PHPSESSID,REMEMBERME,_ga,_gat)和cookie参数,它可以来自此?嗨,谢谢你的回答,但不幸的是,它在生产环境中执行完全相同的操作后端返回给代理的头是什么?我的头似乎有很好的价值。我的操作的响应头有以下内容:(cache-control=>public,s-maxage=600,x-debug-token=>1df192)我不确定请求头是否必须与cache.PS有关。不要忘记,除非指定了其他配置,否则通过客户端/后端发送cookie将完全禁用缓存。抱歉,我不知道什么是VCL(搜索后的Varnish配置语言),但我不知道如何找到它。同一操作的我的请求头在请求头中有一个cookie部分(PHPSESSID、REMEMBERME、_ga、_gat)和cookie参数,它可以来自这个?