简体   繁体   English

带CDN的PHP缓存头

[英]PHP Cache Headers with CDN

I am trying the php header() function to set caching headers to my page. 我正在尝试php header()函数来将缓存头设置为我的页面。 I have a CDN that caches the http requests. 我有一个CDN,可以缓存http请求。 What I am trying to achieve here is that the CDN should cache my page for 2 days, and the browser should check for new version to the CDN every 5 minutes. 我要在这里实现的是CDN应该将我的页面缓存2天,浏览器应该每5分钟检查一次CDN的新版本。

Cache-Control: max-age=300, s-maxage=172800, public

Does this avoe cache header work? 此avoe缓存标头是否起作用?

Does this avoe cache header work? 此avoe缓存标头是否起作用?

Why don't you know from your traffic? 您为什么不知道自己的流量?

Manual : 手册

s-maxage
   If a response includes an s-maxage directive, then for a shared
   cache (but not for a private cache), the maximum age specified by
   this directive overrides the maximum age specified by either the
   max-age directive or the Expires header.

Yes, it should work - but makes no sense to use a shorter expiry time on the client than on an intermediate proxy (unless the client is likely to move between different CDN zones and the content is CDN zone specific). 是的,它应该可以工作-但在客户端上使用比在中间代理上更短的到期时间是没有意义的(除非客户端很可能在不同的CDN区域之间移动,并且内容是特定于CDN区域的)。

The expires header is the one you are looking for, it tells all caches how long the associated representation is fresh for. expires标头是您要寻找的标头,它告诉所有高速缓存关联表示形式的有效时间。 After that time, caches will always check back with the origin server to see if a document is changed. 在那之后,缓存将始终与原始服务器进行核对,以查看文档是否已更改。

Also, if your pages are not password protected, use must-revalidate . 另外,如果您的页面没有密码保护,请使用must-revalidate

You would have a method at the CDN to set your TTL to 2 days 您可以在CDN上将TTL设置为2天

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM