文件缓存的php类库

2018-01-09 17:00:37103572查看评论(1)
简介:

<?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类库

申明:本站所有资源都是转载各大下载站,或由网友投稿发布,请自行检测软件的完整性,如有侵权请联系我们删除下架,联系方式:admin@php.cn

相关推荐

文件缓存的php类库

文件缓存的php类库
96871

PHP文件缓存类库

PHP文件缓存类库
107769

PHP的文件缓存类

PHP的文件缓存类
74338

PHP文件缓存类

PHP文件缓存类
61978

ThinkPHP文件缓存类

ThinkPHP文件缓存类
1025130

php文件页面缓存类

php文件页面缓存类
62769

php中使用文件缓存类

php中使用文件缓存类
5059144

php实现文件缓存类

php实现文件缓存类
57370
网页评论
最新评论
松坤
  • 松坤
  • 反反复复付分付付付付付
  • 2019-04-01 16:56:35发表+0回复