
程序名称:CacheManager
开发者/组织名称:Alexander Stepanenko
运行环境:php+mysql,php+文本
官方网站:http://www.blog.wolfden.com.ua/
下载地址:
请下载附件中的源码,不要直接复制 (已下载 634 次)文章来源: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;
}
}
?>
相关日志
PHP MSN Class MSN机器人使用,或者给MSN、雅虎通发消息
PhpGrid
Php On Trax 国外开源框架
PHPDevShell 国外开源高速的应用程序开发框架
Cacti基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测
PHP MSN Class MSN机器人使用,或者给MSN、雅虎通发消息
PhpGrid
Php On Trax 国外开源框架
PHPDevShell 国外开源高速的应用程序开发框架
Cacti基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测
中查看更多“CacheManager PHP缓存管理类”相关内容
中查看更多“CacheManager PHP缓存管理类”相关内容
中查看更多“CacheManager PHP缓存管理类”相关内容
中查看更多“CacheManager PHP缓存管理类”相关内容
中查看更多“CacheManager PHP缓存管理类”相关内容
中查看更多“CacheManager PHP缓存管理类”相关内容
中查看更多“CacheManager PHP缓存管理类”相关内容
中查看更多“CacheManager PHP缓存管理类”相关内容最后编辑: shuguang 编辑于2007/12/08 08:56
cache_TS
Cached XSL


















