【发布时间】:2012-01-22 01:38:31
【问题描述】:
我想缓存多个在每小时(xx:00:01)开始时显示不同数据的php页面?
到目前为止,我已经找到了一种从访问(或修改文件)时缓存页面 +1 小时的方法,但是如果用户在 xx:59:00 访问该页面,那么在 xx+1: 00:01,他会看到缓存的页面数据,而不是新显示的数据。
最好使用 .htaccess,我需要写什么来获得常规的“最小时”缓存到期?
最终代码(非 htaccess):
$nexthour = mktime(date("H")+1, 00, 20) - mktime();
header("Cache-Control: public, must-revalidate, max-age=".$nexthour.", s-maxage=".$nexthour);
在每一页的顶部。
【问题讨论】:
-
你也许可以做一些与时间相关的重写:httpd.apache.org/docs/2.2/rewrite/advanced.html#time-dependent
-
我认为仅使用 .htaccess 中可用的指令是不可能的。我知道的唯一能够支持服务器端 HTTP 缓存的模块是 mod_cache,但它的指令不能在 .htaccess 文件上下文中使用。
标签: php apache .htaccess caching mod-expires