当前位置: 首页  >  下载站  >  类库  >  其它类库  >  文件缓存的php类库

文件缓存的php类库

文件缓存的php类库

文件缓存的php类库
分类:   类库下载 / 其它类库 发布时间:  2018-01-09 访问量:  2696
下载量:  108
点击下载
更多>

最新下载

50个优秀经典PHP算法大集合

经典PHP算法,学习优秀的思想 , 开拓思维
2259 2020-03-26

PHPExcel-1.8类库(值得收藏!)

PHPExcel 操作Office Excel 文档的PHP类库
11496 2018-09-26

依赖注入容器的PHP库

依赖注入容器的PHP库
379 2018-01-26

小巧的优化图片的PHP库

小巧的优化图片的PHP库
592 2018-01-26

提取GIF动画帧信息的PHP库

提取GIF动画帧信息的PHP库
260 2018-01-26

面向对象流包装PHP库

面向对象流包装PHP库
250 2018-01-26

远程文件下载php类库

远程文件下载php类库
660 2018-01-25

两表合并成一张新表的php类库

两表合并成一张新表的php类库
386 2018-01-25

静态文件生成的php类库

静态文件生成的php类库
370 2018-01-25

php小型日历类库

php小型日历类库
532 2018-01-25
更多>

最新教程

下载首页 / 类库下载 / 其它类库
<?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缓存类库,需要的朋友可以下载使用,可以通过文件缓存,大大缓解数据库的压力

本站所有资源都是由网友投搞发布,或转载各大下载站,请自行检测软件的完整性!本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!如有侵权请联系我们删除下架,联系方式:admin@php.cn

相关推荐

远程文件下载php类库

远程文件下载php类库
其它类库
2018-01-25

静态文件生成的php类库

静态文件生成的php类库
其它类库
2018-01-25

生成excel文件到指定目录的函数php类库

生成excel文件到指定目录的函数php类库
其它类库
2018-01-20

获取文件的mime typePHP类库

获取文件的mime typePHP类库
其它类库
2018-01-20

生成Excel等文档的php类库

生成Excel等文档的php类库
其它类库
2018-01-16

简单高效的文件缓存php类

简单高效的文件缓存php类
其它类库
2018-01-12

文件缓存的php类库

文件缓存的php类库
其它类库
2018-01-09

添加水印,日期,缩略图的多文件上传的php类

添加水印,日期,缩略图的多文件上传的php类
其它类库
2018-01-09

热门下载

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号