文件缓存的php类库
class CacheLayer{
protected $root = "";
protected $cache = "";
protected $key = "";
protected $life = 0;
public function __construct($key, $root = "/cachelayer"){
$this->root = $_SERVER["DOCUMENT_ROOT"].$root;
$this->key = $key;
}
public function expired($life_span){
$this->life = $life_span;
$file = $this->root."/".$this->key.".cachelayer";
if(is_file($file)){
$mtime = filemtime($file);
return (time() >= ($mtime + $this->life));
}else{
return true;
}
}
public function put($content){
$file = $this->root."/".$this->key.".cachelayer";
if(!is_dir(dirname($this->root))){
return false;
}
$this->delete();
$content = json_encode($content);
return (bool)file_put_contents($file, $content);
}
public function get(){
$file = $this->root."/".$this->key.".cachelayer";
if(is_file($file)){
return json_decode(file_get_contents($file), true);
}
return array();
}
public function delete(){
$file = $this->root."/".$this->key.".cachelayer";
if(is_file($file)){
unlink($file);
return true;
}
return false;
}
}
?>
这是一份很好用的PHP缓存类库,需要的朋友可以下载使用,可以通过文件缓存,大大缓解数据库的压力
申明:php中文网下载站匠心打造专业的IT资源下载站!一切资源免费,来源网络收集,请自行检测软件的完整性。交流QQ群:916808767