php 文件缓存函数
代码如下:
function createHashDir($sign) { $md5 = md5($sign); if(!is_dir(MB_CACHE)) mkdir(MB_CACHE); for($i=1;$i<=4;$i++) { $dir .= $md5{$i}.'/'; if(!is_dir(MB_CACHE.$dir)) { mkdir(MB_CACHE.$dir); } } return MB_CACHE.$dir; } function setCacheFile($data,$sign = 'a',$type = 'array',$id = '') { $cacheDir = $this -> createHashDir($sign); if(!empty($data)) { $id = $id ? $id : $sign; $cacheFile = $cacheDir.$id.'.php'; $content = $type == 'array' ? var_export($data,true) : $data; file_put_contents($cacheFile,'<?php $'.$sign.' = '.$content.'; ?>'); } } function getCacheFile($sign = 'a',$id = '') { $cacheDir = $this -> createHashDir($sign); $id = $id ? $id : $sign; $cacheFile = $cacheDir.$id.'.php'; if(is_file($cacheFile) && include_once($cacheFile)) { return $$sign; } } function getCacheFilePath($sign = 'a',$id = '') { $cacheDir = $this -> createHashDir($sign); $id = $id ? $id : $sign; return $cacheDir.$id.'.php'; } function delCacheFile($sign = 'a') { $cacheDir = $this -> createHashDir($sign); $id = $id ? $id : $sign; $cacheFile = $cacheDir.$id.'.php'; $this -> del_file($cacheFile); }
相关推荐
AnLeYe 2013-10-04
oraclestudyroad 2010-03-09
82387067 2020-08-15
playis 2020-06-16
GearUpCloud 2020-06-13
xiaoemo0 2020-05-04
阿狸写代码 2020-04-14
拉斯厄尔高福 2020-04-11
小木兮子 2019-11-27
cmsmdn 2019-11-05
MrQuinn 2017-07-23
jacktangj 2019-10-28
86403969 2019-10-23
adeyi 2018-11-24
oDongTianShuiYue 2019-03-18
panmezihuan0 2018-11-24
香帅 2017-04-21
paypalmts 2019-06-30