Nov 10

CacheManager PHP缓存管理类 不指定

shuguang , 16:20 , Cache , 评论(0) , 引用(0) , 阅读(12307) , Via 本站原创 | |
程序名称:CacheManager
开发者/组织名称:Alexander Stepanenko
运行环境:php+mysql,php+文本
官方网站:http://www.blog.wolfden.com.ua/
下载地址:
请下载附件中的源码,不要直接复制 (已下载 1490 次)

文章来源:http://www.OSphp.com.cn //开源代码OSPHP.COM.Cn
程序介绍:
This class can be used to cache arbitrary data in files.

It can check if the cache with a certain key already exists. If it exists and it is not expired, it can return the cached data. Otherwise it can store newly generated data in a cache file with the given key.

The class can be configured to set the cache life time and the root directory of where all the cache files will be stored.

引用

class CacheManager extends Entity {

  /**
  * Contains number of seconds - timeframe for storing cache
  *
  * @var int
  * @name timeframe
  * @access private
  */
  var $timeframe;

  /**
  * Contains name of the cache root directory
  *
  * @var string
  * @name _cacheRoot //OSPHP.COM.Cn开源
  * @access public
  */
  var $_cacheRoot;

  /**
  * Constructor, defines timeframe for storing cache
  *
  * @param int number of seconds
  * @param int number of minutes
  * @param int number of hours
  * @param int number of days
  * @param int number of month
  * @param int number of years
  */
  function CacheManager ($second = 0, $minute = 0, $hour = 0, $day = 0, $month = 0, $year = 0) {
    $this->timeframe = mktime (2 + $hour, 0 + $minute, 0 + $second, 1 + $month, 1 + $day, 1970 + $year);
  }

  /**
  * Checks if cache contains file no older than timeframe
  *
  * @return string
  */
  function CheckCache ($model, $key = 0, $fname = '', $timeframe = 0) {
    $result   = 0;
//开源代码OSPHP.COM.Cn

    $filename = ($fname ? $fname : $this->_cacheRoot.strtolower($model).'/'.($key ? $key : 'model').'.html');
    if ( file_exists ($filename) ) {
      $tframe = ($timeframe ? $timeframe : $this->timeframe);
      if (time() - filemtime ($filename) < $tframe) $result = $this->RetrieveData ($filename);
    }
    return $result;
  }

  /**
  * Read the content of the file
  *
  * @param string filename
  * @return string
  */
  function RetrieveData ($filename) {
    $fp      = fopen ($filename, 'r');
    $content = fread ($fp, filesize ($filename));
    fclose ($fp);
    return $content;
  } //OSPHP.com.CN

  /**
  * Store content in the file
  *
  * @return string
  */
  function SaveToCache ($model, $key = 0, $content = '', $fname = '') {
    $filename = ($fname ? $fname : $this->_cacheRoot.strtolower($model).'/'.($key ? $key : 'model').'.html');
    $fp       = fopen ($filename, 'w+');
    fwrite ($fp, $content);
    fclose ($fp);
    return $filename;
  }

}
?>
收藏本文到网摘: 添加到“Google书签” 添加到“Yahoo收藏” 添加到“QQ书签” 搜狐网摘 添加到“百度搜藏” 添加到“新浪ViVi收藏夹” 添加到“Del.icio.us” 添加到“365天天网摘” 添加到“天极网摘” 我摘·网摘·网络书签 添加到“POCO网摘” YouNote网摘 添加到“和讯网摘” 添加到“Bolaa博客收录中心” 添加到“igooi网摘” 添加到“天下图摘”
  • 中查看更多“CacheManager PHP缓存管理类”相关内容
  • 中查看更多“CacheManager PHP缓存管理类”相关内容
  • 中查看更多“CacheManager PHP缓存管理类”相关内容
  • 中查看更多“CacheManager PHP缓存管理类”相关内容
  • 中查看更多“CacheManager PHP缓存管理类”相关内容
  • 中查看更多“CacheManager PHP缓存管理类”相关内容
  • 中查看更多“CacheManager PHP缓存管理类”相关内容
  • 中查看更多“CacheManager PHP缓存管理类”相关内容

  • 最后编辑: shuguang 编辑于2007/12/08 08:56
    Tags: , , , , ,
    发表评论

    昵称

    网址

    电邮

    打开HTML 打开UBB 打开表情 隐藏 记住我 [登录系统] [注册]