HTTP头 Pragma:no-cache 缓存来源

今天给同事分享了一下前端性能优化,在介绍了php文件缓存的方法后,发现一个AJAX请求的文件,在请求头中始终有一个:Pragma:no-cache,导致这个文件不能被浏览器缓存。接着发现这个站几乎所有动态页面都有这个参数Pragma:no-cache。

开始怀疑是不是设置了Cache-control:no-cache导致的,但查遍程序没发现。怀疑服务器的配置,没什么异常的。最后,同事定位到了页面开始的session_start()身上。。。


问题果然出现在它session身上!

session.cache_limiter string 
session.cache_limiter 指定会话页面所使用的缓冲控制方法(none/nocache/private/private_no_expire/public)。默认为 nocache。参见 session_cache_limiter()。

string session_cache_limiter ( [string cache_limiter] )

session_cache_limiter() returns the name of the current cache limiter. If cache_limiter is specified, the name of the current cache limiter is changed to the new value. 

The cache limiter defines which cache control HTTP headers are sent to the client. These headers determine the rules by which the page content may be cached by the client and intermediate proxies. Setting the cache limiter to nocache disallows any client/proxy caching. A value of public permits caching by proxies and the client, whereas private disallows caching by proxies and permits the client to cache the contents. 

In private mode, the Expire header sent to the client may cause confusion for some browsers, including Mozilla. You can avoid this problem by using private_no_expire mode. The expire header is never sent to the client in this mode. 

The cache limiter is reset to the default value stored in session.cache_limiter at request startup time. Thus, you need to call session_cache_limiter() for every request (and before session_start() is called).


当启用了session后,session.cache_limiter就被默认设置为nocache,所以就在http头里发送no-cache信息,导致页面不会被缓存。
当然一般需要缓存的文件是不需要session的,因此去掉头部的session_start()即可。
如果实在需要在启用session后还需要把这个页面缓存,则需要在session_start之前设置下session_cache_limiter('public')。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值