【问题标题】:Symfony2 Varnish NGINX cache / DebugToolbarSymfony2 Varnish NGINX 缓存 / DebugToolbar
【发布时间】:2012-07-01 08:15:24
【问题描述】:

我正在尝试将清漆缓存与 symfony2 一起使用。 设置是 Varnish -> NGNIX -> php-fpm

我的代码:

public function indexAction($city_url)
{

    $response = new Response();
    $response->setETag('foobar123fo');
    if ($response->isNotModified($this->getRequest())) {
        // return the 304 Response immediately
        return $response;
    }

    $data = array('randA'=> rand() );
    $response = $this->render('Foo:Event:index.html.twig', $data);

    $response->setCache(array(
        'public'        => true,
    ));
    $response->setETag('foobar123fo');
    $response->setSharedMaxAge(10); 

    return $response;

这按预期工作 - 我得到了缓存命中,但 Symfony 的调试工具栏也被缓存了。谁能告诉我,如何排除工具栏被缓存?我想看看,在提供缓存结果时,确实没有 SQL 查询。

非常感谢!

【问题讨论】:

    标签: debugging caching symfony nginx varnish


    【解决方案1】:

    如果页面在 Varnish 上完全缓存,请求甚至不会访问您的 Web 服务器。不仅没有进行 SQL 查询,而且根本没有调用 Symfony。

    调试工具栏是页面的一部分,这就是它被缓存的原因。再次... Symfony 仅在第一个请求时调用。

    再次阅读官方文档中的HTTP Cache 章节。里面推荐了两篇文章,也值得一读:

    【讨论】:

      猜你喜欢
      • 2012-05-02
      • 2020-04-07
      • 2017-02-08
      • 2016-10-08
      • 1970-01-01
      • 2015-10-21
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多