Home >Backend Development >PHP Tutorial >PHP file caching function_PHP tutorial

PHP file caching function_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:24:151122browse

复制代码 代码如下:

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,'');
}
}
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);
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324377.htmlTechArticle复制代码 代码如下: 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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn