Symfony 3.4 http缓存,始终为Cache-Control:max-age = 0,必须重新验证,私有 [英] Symfony 3.4 http cache , always Cache-Control: max-age=0, must-revalidate, private

查看:142
本文介绍了Symfony 3.4 http缓存,始终为Cache-Control:max-age = 0,必须重新验证,私有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加注释

 * @Cache(expires="+10 hours", public=false) 

或在控制器

$maxAge = 60*60;
$response->setExpires(Carbon::create()->addHour());
$response->setSharedMaxAge($maxAge);
$response->setPublic();
$response->setMaxAge($maxAge);

并且仍然有Cache-Control: max-age=0, must-revalidate, private

应用使用会话,用户已登录-我想要-缓存私有,但无济于事-我总能得到这个.

App use sessions, user is login - I want - cache private, but nothing work - I always get this.

我添加了FOS\HttpCacheBundle\FOSHttpCacheBundle()

(只是添加)希望它可以覆盖symfony缓存并允许将发送缓存设为私有-但什么都没有改变.

(just add) Have hope to it override symfony cache and allow send cache private - but nothing change.

推荐答案

从Symfony 3.4和4.0开始,此行为是新的.如果用户会话已初始化,它将始终按照您的问题中的说明设置标头.

This behaviour is new as of Symfony 3.4 and 4.0. If a user session has been initialized it will always set the headers as described in your question.

在Symfony 4.1中引入的功能可以覆盖此行为.但是,由于这是一项新功能,因此不会反向移植到Symfony 3.4.

Introduced in Symfony 4.1 you can override this behaviour. However as this is a new feature this will not be backported to Symfony 3.4.

$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');

您可以在Symfony文档中了解以下内容: HTTP缓存和用户会话

You can read about this in the Symfony documentation: HTTP Caching and User Sessions

这篇关于Symfony 3.4 http缓存,始终为Cache-Control:max-age = 0,必须重新验证,私有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆