尚未完善,大家共同研究
<?php /* 缓存类 of www.vgot.cn by pader 09-1-30 13:34 */ define('CACHE_DIR',dirname(__FILE__).'/cache'); class cache { var $cache = array(); //获取缓存 function getCache($cacheName) { include $this->cacheFile($cacheName); $this->cache[$cacheName] = $cache[$cacheName]; return $this->cache[$cacheName]; } //存储缓存 function saveCache($cacheName,$cacheVar){ $cacheCode = "<?php\r\n//Cache create at ".date('Y-m-d H:i:s')."\r\n"; $cacheCode .= '$cache[\''.$cacheName.'\'] = '; $cacheCode .= $this->createVarCode($cacheVar); $cacheCode .= ";\r\n"; return $this->writeFile($this->cacheFile($cacheName),$cacheCode) ? true : false; } //创建缓存变量原生态代码 function createVarCode($myVar,$level=0) { $tabEnd = ''; for($i=0;$i<$level;$i++) { $tabEnd .= "\t"; } $tab = $tabEnd."\t"; if(is_array($myVar)) { $varCode = "array(\r\n"; foreach($myVar as $key => $val) { $key = is_numeric($key) ? $key : '\''.$key.'\''; if(is_array($val)) { $varCode .= $tab.$key.' => '.$this->createVarCode($val,$level + 1); } else { $varCode .= $tab.$key.' => \''.$this->addslashes($val).'\''; } $varCode .= ",\r\n"; } $varCode = substr_replace($varCode,'',-3,1)."$tabEnd)"; } else { $varCode = '\''.$this->addslashes($myVar).'\''; } return $varCode; } function addslashes($text) { $text = addcslashes($text,'\\'); $text = addcslashes($text,'\''); return $text; } //返回缓存文件地址 function cacheFile($cacheName) { $cacheFile = CACHE_DIR.'/'.$cacheName.'.php'; return $cacheFile; } function deleteCache($cacheName) { return @unlink($this->cacheFile($cacheName)) ? true : false; } function printCache() { print_r($this->cache); } //写文件 function writeFile($fileName,$content,$wmode='w'){ $s = false; if($fp = @fopen($fileName,$wmode)) { if(flock($fp,LOCK_EX)) { $s = @fwrite($fp,$content) ? true : false; flock($fp,LOCK_UN); fclose($fp); } } return $s; } }
这一段PHP代码写得不错啊,学习了,谢谢.
你好,之前的域名buluka.cn暂停使用,更改为www.walleve.com 友情链接更改请求: 将JECCY's blog 修改为 Walleve-Team 地址更换为:http://www.walleve.com 描述为:相濡以沫,不若相忘于江湖