Pis*_*tos 5 mod-rewrite mod-cache apache-2.2
我有一个 PHP 站点,其中包含许多动态生成的页面。我试图求助于 mod_cache 来帮助提高性能,因为在大多数情况下,内容在一天内不会改变。
我已经尽我所能配置了 mod_cache,遵循网络上的示例,包括apache.org 上的 mod_cache 页面。当我设置时LogLevel debug,我会看到一些有关 [未] 发生的缓存的信息。有很多这样的行:
[Fri Jun 01 17:28:18 2012] [debug] mod_cache.c(141): Adding CACHE_SAVE filter for /foo/bar
[Fri Jun 01 17:28:18 2012] [debug] mod_cache.c(148): Adding CACHE_REMOVE_URL filter for /foo/bar
Run Code Online (Sandbox Code Playgroud)
这很好,因为我已经设置了CacheEnable disk /foo, 来表明我想要缓存 /foo 下的所有内容。我是 mod_cache 的新手,但我对这些行的理解是,这只是意味着 mod_cache 已经承认应该缓存 URL,但是应该有更多行表明它正在将数据保存到缓存,并且然后稍后在对同一 URL 的后续点击中检索它们。
无论是否使用 F5 刷新,或使用不同的浏览器或不同的计算机,我都可以点击相同的 URL 直到我脸色发青。日志中总是显示那对行,没有别的。
当我设置时CacheEnable disk /,我会看到更多的活动。但是我不想缓存整个站点,而且站点有很多很多不同的子路径,所以我不想修改代码来no-cache在所有必要的地方设置标题。
我会提到这里正在使用 mod_rewrite,将 /foo/bar 重写为类似的内容index.php?baz=/foo/bar,但我的理解是 mod_cache 使用的是重写前的 URL,而不是重写后的 URL。
据我所知,我的响应头不会妨碍缓存。这是一次命中的示例:
Cache-Control:must-revalidate, max-age=3600
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:16790
Content-Type:text/html
Date:Fri, 01 Jun 2012 21:43:09 GMT
Expires:Fri, 1 Jun 2012 18:43:09 -0400
Keep-Alive:timeout=15, max=100
Pragma:
Server:Apache
Vary:Accept-Encoding
Run Code Online (Sandbox Code Playgroud)
mod_cache 配置如下:
CacheRoot /var/cache/apache2/
CacheDirLevels 3
CacheDirLength 2
CacheEnable disk /foo
Run Code Online (Sandbox Code Playgroud)
什么阻碍了 mod_cache 执行缓存工作?
这是我的配置并且运行良好:
<IfModule mod_disk_cache.c>
CacheEnable disk /
CacheRoot /var/cache/apache2/mod_disk_cache
CacheIgnoreCacheControl On
CacheMaxFileSize 2500000
CacheIgnoreURLSessionIdentifiers jsessionid
CacheIgnoreHeaders Set-Cookie
</IfModule>
Run Code Online (Sandbox Code Playgroud)
您需要有 CacheIgnoreURLSessionIdentifiers 适合您的需求,所以也许在 PHP 上您需要
CacheIgnoreURLSessionIdentifiers PHPSESSID
Run Code Online (Sandbox Code Playgroud)
问候詹宁
| 归档时间: |
|
| 查看次数: |
8717 次 |
| 最近记录: |