php 文件缓存函数

yipeiwu_com5年前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自定义加密与解密程序实例

本文实例讲述了php自定义加密与解密程序。分享给大家供大家参考。具体分析如下: PHP3 Cryption是一个非常容易被破解,不安全的加密功能,不应该是非常重要的东西用,虽然加密是好的...

php PDO实现的事务回滚示例

本文实例讲述了php PDO实现的事务回滚。分享给大家供大家参考,具体如下: $servername="localhost"; $username="root"; $password...

PHP编程实现脚本异步执行的方法

本文实例讲述了PHP编程实现脚本异步执行的方法。分享给大家供大家参考,具体如下: php语言得用fsockopen()函数,实现脚本异步运行,代码如下 异步请求函数(用debug参数若为...

用PHP生成html分页列表的代码

<?php $db = mysql_connect("127.0.0.1","root","*******") or die("cant't...

php开发中的页面跳转方法总结

页面跳转可能是由于用户单击链接、按钮等触发的,也可能是系统自动产生的。页面自动跳转在WEB开发中经常用到,而且根据需求可以采用不同的跳转方式,比如提示操作信息后延时跳转等, 本文总结了W...