加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php 文件缓存函数

发布时间:2020-05-24 18:54:57 所属栏目:PHP 来源:互联网
导读:php 文件缓存函数,需要的朋友可以参考下。

<div class="codetitle"><a style="CURSOR: pointer" data="3585" class="copybut" id="copybut3585" onclick="doCopy('code3585')"> 代码如下:<div class="codebody" id="code3585">
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);
}

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读