PEAK XOOPS - Re: 最速キャッシュハックの実験版放流 in englishin japanese

Re: 最速キャッシュハックの実験版放流

Target News
Subject 最速キャッシュハックの実験版放流
Summary 「最速キャッシュハック」を実験版として公開します。http://www.peak.ne.jp/xoops/md/mydownloads/singlefile.php?lid=67&cid=2XOOPS初(?)のページキャッシュシステムで、XOOPSの動作原理に基づいたキャッシュ制御にその特徴があります。もっとも特徴的なのは、redirect_...

List posts in the topic

normal Re: 最速キャッシュハックの実験版放流

msg# 1
depth:
0
Previous post - Next post | Parent - Children.1 | Posted on 2006/1/14 14:15
nobunobu  上等兵   Posts: 25
実験のついでに、ブラウザキャッシュも有効活用するようにして、サーバの負荷をへらすことを考えてみました。
実は、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' ) ;
等としています。
こうすれば、ブラウザキャッシュが有効になって、サーバのリクエスト回数の減少と
トラフィックの軽減に繋がると思います。
Votes:0 Average:0.00

Posts tree

  Advanced search


Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!