PHP头条
热点:

php 实现文件缓存函数代码


  1. <?php
  2.  /**
  3.  * 读取或设置缓存
  4.  *
  5.  * @access  public
  6.  * @param   string  $name   缓存名称
  7.  * @param   mixed   $value  缓存内容, null删除缓存
  8.  * @param   string  $path   缓存路径
  9.  * @return  mixed
  10.  */
  11.  function cache($name, $value = , $path = )
  12.  {
  13.      return false;   //调试阶段, 不进行缓存
  14.      $path = empty($path) ? ROOT_PATH . /Runtime/Data/ : $path;
  15.      $file = $path . $name . .php;
  16.      if (empty($value)) {
  17.          //缓存不存在
  18.          if (!is_file($file)) {
  19.              return false;
  20.          }
  21.          // 删除缓存
  22.          if (is_null($value)) {
  23.              unlink($file);
  24.              return true;
  25.          }
  26.          $data = include $file;
  27.          return $data;
  28.      }
  29.      $value = var_export($value, true);
  30.      $value = "<?php !defined(ROOT_PATH) && exit(Access Denied); return {$value}; ?>";
  31.      return file_put_contents($file, $value);
  32. }
  33. //函数调用
  34. cache(name, array(a, b, c)); //写入缓存 name为缓存名称, 后面那个数组是缓存的内容
  35. cache(name); //读取缓存
  36. cache(name, null); //删除缓存
  37. ?>

www.phpzy.comtrue/phprm/24969.htmlTechArticlephp 实现文件缓存函数代码 ?php /** * 读取或设置缓存 * * @access public * @param string $name 缓存名称 * @param mixed $value 缓存内容, null删除缓存 * @param string $path 缓存路径 * @return mixed */ function ca...

相关文章

    暂无相关文章

PHP之友评论

今天推荐