php文件保存类库,文件缓存的php类库

文件缓存的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值