【问题标题】:X-Symfony-Cache always missX-Symfony-Cache 总是错过
【发布时间】:2016-06-29 03:48:38
【问题描述】:

我正在使用 Symfony 2.6 HTTP 缓存,我正在遵循 Symfony 烹饪书 here 中的所有说明

但是,为什么响应总是 X-Symfony-Cache: MISS。我尝试修改私有标题上的 AppModification.php 擦除数组。响应头是 X-Symfony-Cache:GET /page: fresh。

修改数组后,我遇到了新问题,当我尝试登录我的网站时,我收到错误或消息页面无法正常工作。

这是我在擦除数组私有标头之前的代码:

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,
    );
} 

响应标头:

缓存控制:私有 连接:保活 内容类型:文本/html;字符集=UTF-8 日期:格林威治标准时间 2016 年 6 月 29 日星期三 03:37:56 保活:超时=5,最大值=100 服务器:Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.30 传输编码:分块 X-Powered-By:PHP/5.5.30 X-Symfony-Cache:GET /page: stale, invalid

我尝试擦除数组私有标头

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,
    );
}

响应标头:

年龄:2 缓存控制:公共,s-maxage=62 连接:保活 内容长度:366990 内容类型:文本/html;字符集=UTF-8 日期:格林威治标准时间 2016 年 6 月 29 日星期三 03:41:56 保活:超时=5,最大值=100 服务器:Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.30 X 内容摘要:en5ea0d5af1ee851007583987e8dfb3a8207874e303363f3d33c412b7f3fe6c12c X-Powered-By:PHP/5.5.30 X-Symfony-Cache:GET /page: stale, invalid, store

任何人都可以帮助我,建议解决这个问题?我不知道了,在任何 Symfony 文档中都找不到。

这里是我的控制器:

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);
}

【问题讨论】:

  • 请显示您的/page 操作的注释。
  • 你是说我的控制器吗?
  • 是的,只是为了检查您是否添加了@Cache 注释或正确修改了您的Response 对象
  • 我只是添加我的控制器代码
  • 尝试在返回前添加$response = $view->getResponse(); $response->setPublic(); $response->setSharedMaxAge(600);。

标签: php apache symfony caching utf-8


【解决方案1】:

Symfony 缓存层就像一个中间 HTTP 缓存,很像 Varnish 的反向代理。

这意味着对于可缓存的响应,它需要是公共的(任何缓存都可以存储它)而不是私有的(只有浏览器缓存可以存储它)。此外,必须使用适当的缓存策略,例如 Cache-Control 标头或 Expires 标头中的 max-age。

【讨论】:

猜你喜欢
  • 2018-03-17
  • 2016-11-11
  • 2018-11-24
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多