実験のついでに、ブラウザキャッシュも有効活用するようにして、サーバの負荷をへらすことを考えてみました。
実は、WordPressの新しい0.6.0 AlphaではRSSなどで同様のことをしているのですが、
function fastestcache_static_content_header($mod_timestamp, $cache_expire=0, $max_lifetime=86400) {
$mod_timestamp = intval($mod_timestamp);
$cache_expire = intval($cache_expire);
$max_lifetime = intval($max_lifetime);
if (empty($cache_expire)) $cache_expire = $mod_timestamp+$max_lifetime;
$etag = md5( $_SERVER["REQUEST_URI"] . $mod_timestamp );
header('Pragma:');
header('Etag: "'.$etag.'"' );
header('Cache-Control: max-age='.$max_lifetime);
header('Expires:'.gmdate('D, d M Y H:i:s',$cache_expire).' GMT');
if(!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$modified_since = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
if ( strpos( $modified_since, ',' ) === false ) $modified_since .= ' GMT';
if (($mod_timestamp==strtotime( $modified_since ))||
(!empty($_SERVER['HTTP_IF_NONE_MATCH'])&&($etag==$_SERVER['HTTP_IF_NONE_MATCH']))){
header('HTTP/1.1 304 Not Modified');
exit();
}
}
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mod_timestamp).' GMT');
}
等という関数を用意して、
fastestcache.php内の、header出力部分を、
$mod_timestamp = @filemtime( $fastestcache_path );
fastestcache_static_content_header($mod_timestamp, $mod_timestamp+$fastestcache_expire,$fastestcache_expire);
// header( 'Expires: Mon, 27 Jul 1997 05:00:00 GMT' ) ;
// header( 'Cache-Control: private, no-store' ) ;
// header( 'Pragma: no-cache' ) ;
等としています。
こうすれば、ブラウザキャッシュが有効になって、サーバのリクエスト回数の減少と
トラフィックの軽減に繋がると思います。