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中的Streams工具

Streams 是PHP提供的一个强有力的工具,我们常常在不经意会使用到它,如果善加利用将大大提高PHP的生产力。 驾驭Streams的强大力量后,应用程序将提升到一个新的高度。 下面是...

PHP判断访客是否手机端(移动端浏览器)访问的方法总结【4种方法】

本文实例总结了PHP判断访客是否手机端(移动端浏览器)访问的方法。分享给大家供大家参考,具体如下: 在平常工作开发中,我们通常需要开发出PC端和移动端两个不同的系统,从而根据访问端的不同...

PHP实现的CURL非阻塞调用类

本文实例讲述了PHP实现的CURL非阻塞调用类。分享给大家供大家参考,具体如下: 前面一篇《PHP实现非阻塞模式的方法》文章讲述了PHP中实现非阻塞模式,其实如果只是HTTP的话,直接用...

php和js实现根据子网掩码和ip计算子网功能示例

php和js实现根据子网掩码和ip计算子网功能示例

本文实例讲述了php和js实现根据子网掩码和ip计算子网功能。分享给大家供大家参考,具体如下: php <?php $ip = '192.168.6.1'; $mask...

PHP XML数据解析代码

复制代码 代码如下: //xml string $xml_string="<?xml version='1.0'?> <users> <user id='3...