php 文件缓存
来源:互联网 发布:weui.js 删除预览图片 编辑:程序博客网 时间:2024/05/18 00:44
class fileCache{ private $cachePath; private $cacheFileName; private $cacheFilePath; private $expiresTime; private $data=""; public function fileCache($cacheTime=10,$cachePath="cache/"){ $this->expiresTime=$cacheTime; $this->cachePath=$cachePath; $this->createCacheName(); } public function setData($data){ $this->data=$data; } public function createCacheName(){ $url=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; $this->cacheFileName=md5($url); $this->cacheFilePath=$this->cachePath.$this->cacheFileName.".php"; } public function buildCache(){ ob_start(); echo $this->data; $content=ob_get_contents(); ob_flush(); ob_clean(); file_put_contents($this->cacheFilePath, $content); } public function readCache(){ $cacheFile=$this->cacheFilePath; if(file_exists($cacheFile)){ include $cacheFile; }else{ return false; } return true; } public function cacheTime(){ $cacheFile=$this->cacheFilePath; if(!file_exists($cacheFile)){ return true; }elseif(fileatime($cacheFile)+$this->expiresTime<=time()){ return true; } return false; } }/////$cache=new fileCache(2, "cache/");if($cache->cacheTime()){ $cache->setData("hello world !"); $cache->buildCache();}else{ $cache->readCache();}
0 0
- PHP缓存之文件缓存
- 初识PHP文件缓存
- 谈PHP文件缓存
- php文件缓存数据
- php文件缓存
- PHP文件缓存secache
- php 文件缓存
- php文件缓存类
- php文件缓存类
- php文件缓存数据
- php 文件缓存类
- PHP文件缓存类
- PHP文件缓存
- php 文件缓存
- PHP实现文件缓存转化内存缓存
- PHP实现文件缓存转内存缓存
- PHP缓存文件的分页
- PHP的文件缓存机制
- 更换android开机动画须选择好正确的压缩格式
- PHP中声明一个空数组
- CMarkup类的成员函数
- div左边固定、右边自适应 和 上边固定、下边自适应
- Android学习:自定义ViewGroup方法总结
- php 文件缓存
- Oracle学习笔记——Oracle和SQL基础
- 新手提权笔记
- Cordova编译Android 22 以上版本,中文目录出错问题的解决办法
- 应用跳转
- 矛与盾——扫描器盲打对主动安全防护的启示
- 使用ThreadGroup模拟线程池
- Redis常用命令
- Repeater控件绑定值的使用