php 文件缓存函数

yipeiwu_com6年前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);
}

相关文章

PHP编码转换函数 自动转换字符集支持数组转换

复制代码 代码如下: // 自动转换字符集 支持数组转换 function auto_charset($fContents, $from='gbk', $to='utf-8') { $f...

PHP如何将XML转成数组

如果你使用 curl 获取的 xml data xml=simplexmlloadstring(data); data[′tk′]=jsondecode(jsonencode(xml),...

Windows2003下php5.4安装配置教程(IIS)

Windows2003下php5.4安装配置教程(IIS)

本文与《Windows2003下php5.4安装配置教程(Apache2.4)》(点击打开链接)为姊妹篇,只是php所用的服务器有点不同,这里一个是Apache2.4,一个是Window...

PHP move_uploaded_file() 函数(将上传的文件移动到新位置)

PHP move_uploaded_file() 函数(将上传的文件移动到新位置)

定义和用法 move_uploaded_file() 函数将上传的文件移动到新位置。 若成功,则返回 true,否则返回 false。 语法 move_uploaded_file(fil...

PHP实现顺时针打印矩阵(螺旋矩阵)的方法示例

本文实例讲述了PHP实现顺时针打印矩阵的方法。分享给大家供大家参考,具体如下: 问题 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵:...