Symfony HTTP Cache-Control标头覆盖

Pio*_*ski 3 caching http cache-control symfony

我前段时间回答过这个问题.

我在Symfony 3.4中的代码.

 $response->setCache([
     'max_age' => 3600,
     'public' => true,
     's_maxage' => 3600,
 ]);


 // (optional) set a custom Cache-Control directive
 $response->headers->addCacheControlDirective('must-revalidate', true);

 return $response;
Run Code Online (Sandbox Code Playgroud)

在某些原因,我仍然得到Cache-Control像这样的其他标题:

Cache-Control: max-age=0, must-revalidate, private, s-maxage=3600
X-Symfony-Cache: GET /: miss
Run Code Online (Sandbox Code Playgroud)

我注意到在Symfony 3.2代码中运行良好,但在3.4中我没有进入publicCache-Control(并且max-age=0看起来也很糟糕).

第二件事是$response在控制器中倾倒- 一切看起来都很好:

#headers: array:2 [?
  "cache-control" => array:1 [?
    0 => "max-age=3600, must-revalidate, public, s-maxage=3600"
  ]
  "date" => array:1 [?
    0 => "Sat, 12 May 2018 18:42:04 GMT"
  ]
]
Run Code Online (Sandbox Code Playgroud)

它是某种Symfony bug吗?我应该报告吗?

ada*_*afr 6

与Symfony 3.4.14相同.花了5个小时才发现自3.4版本以来symfony会覆盖Cache-Control标头(如果存在会话)(4.1文档).

Symfony 3.4文档没有此信息.

  • 在4.1中,您可以使用`$ response-> headers-> set(AbstractSessionListener :: NO_AUTO_CACHE_CONTROL_HEADER,'true')禁用此行为; (3认同)