php缓存类

释放双眼,带上耳机,听听看~!

<?php
class Cache
{
 static function S($name,$data='',$time=100,$path='cache/')
 {
  $split = '|–|–|';
  $prefix = '.cache.php';
  $file = $path.md5(strtolower($name)).$prefix;
  //如果$data为空,刚为读取缓存
  if(empty($data))
  {
   if(is_file($file))
   {
    $cache = file_get_contents($file);
    preg_match('/<\?php \/\/\/(.\*)\ ?>/is',$cache,$rs);

    $cache = $rs[1];
$data = explode($split,$cache);
$time = intval($data[0]);
$cache = $data[1];
if($time < time()) return null;
else return unserialize($cache);
}
else return null;
}
//否则为写缓存
else
{
$time = time() + $time;
$data = serialize($data);
$data = '<?php ///'.$time.$split.$data.' ?>';
$folder = dirname($file);
mk_dir($folder);
$fp = @fopen($file,'w+');
@fwrite($fp,$data);
@fclose($fp);
}
}
}

if(!function_exists('mk_dir')) {  // 循环创建目录  function mk_dir($dir, $mode = 0777)  {   if (is_dir($dir) || @mkdir($dir,$mode)) return true;   if (!mk_dir(dirname($dir),$mode)) return false;   return @mkdir($dir,$mode);  } } ?>

给TA打赏
共{{data.count}}人
人已打赏
安全技术

C++ explicit关键字

2022-1-11 12:36:11

气候知识

2011年第19号台风“尼格”

2011-10-3 17:34:33

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索