cache研究

读、写 一个memcache的平均时间:0.00020 s

读、写 一个文件的时间 0.00012 s

new一个memcache对象,然后链接,需要的时间: 0.00012 s

结论:读文件比memcached 快

pear: Cache_Lite

单独列出来了,见 pear::Cache Lite

最简单的文件缓存方式

/*
 * 文件缓存 作者:kenvinqu  Email:kenvinqu@gmail.com
 */
$news_id = 5;
 
$expire_time = 60;			//缓存过期时间
$filePath = "data/news_{$id}.txt";	//缓存文件路径
 
$code = @file_get_contents($filePath);	//获取缓存内容
 
//如果获取失败     或者 缓存内容为空  或者    缓存文件的修改时间 早于$expire_time前  ,就重构缓存 
if ($code == false || empty($code) ||   (time() - filemtime($filePath)) > $expire_time  ) {
	
	//去数据库去值,或者复杂运算
	$str = "要缓存的内容 . 当前时间是:". date("Y-m-d H:i:s") ;
 
 
	$code = $str ;	//要缓存的内容
	file_put_contents($filePath,$code);	//写文件,创建缓存
}
 
echo $code ;	//已经获得了缓存值

这样好像没什么问题吧? — 屈伟 2007/07/12 15:09

php/cache.txt · 最后更改: 2007/10/26 07:20 由 58.31.118.11
到顶部
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0 红麦软件 红麦软件