| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- // +----------------------------------------------------------------------
- // | Fanwe 方维直播系统
- // +----------------------------------------------------------------------
- // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: 云淡风轻(1956838968@qq.com)
- // +----------------------------------------------------------------------
- class CacheService
- {//类定义开始
- /**
- +----------------------------------------------------------
- * 是否连接
- +----------------------------------------------------------
- * @var string
- * @access protected
- +----------------------------------------------------------
- */
- protected $connected ;
- /**
- +----------------------------------------------------------
- * 操作句柄
- +----------------------------------------------------------
- * @var string
- * @access protected
- +----------------------------------------------------------
- */
- protected $handler ;
- /**
- +----------------------------------------------------------
- * 缓存存储前缀
- +----------------------------------------------------------
- * @var string
- * @access protected
- +----------------------------------------------------------
- */
- protected $prefix='~@';
- /**
- +----------------------------------------------------------
- * 缓存连接参数
- +----------------------------------------------------------
- * @var integer
- * @access protected
- +----------------------------------------------------------
- */
- protected $options = array();
- /**
- +----------------------------------------------------------
- * 缓存类型
- +----------------------------------------------------------
- * @var integer
- * @access protected
- +----------------------------------------------------------
- */
- protected $type ;
- /**
- +----------------------------------------------------------
- * 缓存过期时间
- +----------------------------------------------------------
- * @var integer
- * @access protected
- +----------------------------------------------------------
- */
- protected $expire ;
- /**
- +----------------------------------------------------------
- * 取得缓存类实例
- +----------------------------------------------------------
- * @static
- * @access public
- +----------------------------------------------------------
- * @return mixed
- +----------------------------------------------------------
- */
- static function getInstance()
- {
- global $distribution_cfg;
- $type = $distribution_cfg["CACHE_TYPE"];
- $cacheClass = 'Cache'.ucwords(strtolower(strim($type)))."Service";
- if(file_exists(APP_ROOT_PATH."system/cache/".$cacheClass.".php"))
- {
- require_once $cacheClass.'.php';
- if(class_exists($cacheClass))
- {
- $cache = new $cacheClass();
- }
- else
- throw_exception('缓存初始化失败:'.$type);
- return $cache;
- }
- else
- {
- require_once 'CacheFileService.php';
- if(class_exists("CacheFileService"))
- $cache = new CacheFileService();
- else
- throw_exception('缓存初始化失败:'.$type);
- return $cache;
- }
- }
-
-
- protected function log_names($name)
- {
- if(!$GLOBALS['distribution_cfg']['CACHE_LOG'])return;
- $name_logs_files = APP_ROOT_PATH."public/runtime/app/~cache_name.log"; //记录被缓存的名称
- if(!file_exists($name_logs_files))
- {
- @file_put_contents($name_logs_files,'');
- }
- else
- {
- if($name!='')
- {
- $names = @file_get_contents($name_logs_files);
- $names = unserialize($names);
- if(is_array($names)&&!in_array($name,$names))
- {
- array_push($names,$name);
- }
- elseif(!is_array($names))
- {
- $names = array();
- array_push($names,$name);
- }
-
- $names = serialize($names);
- @file_put_contents($name_logs_files,$names);
- }
- }
- }
-
- protected function get_names()
- {
- if(!$GLOBALS['distribution_cfg']['CACHE_LOG'])return;
- $name_logs_files = APP_ROOT_PATH."public/runtime/app/~cache_name.log"; //记录被缓存的名称
- if(file_exists($name_logs_files))
- {
- $names = @file_get_contents($name_logs_files);
- $names = unserialize($names);
- if(is_array($names))
- {
- return $names;
- }
- else
- {
- return array();
- }
- }
- else
- {
- return array();
- }
- }
-
- protected function del_name_logs()
- {
- if(!$GLOBALS['distribution_cfg']['CACHE_LOG'])return;
- $name_logs_files = APP_ROOT_PATH."public/runtime/app/~cache_name.log"; //记录被缓存的名称
- @unlink($name_logs_files);
- $GLOBALS['db']->query("update ".DB_PREFIX."conf set `value` = 0 where name = 'PROMOTE_MSG_LOCK' or name ='DEAL_MSG_LOCK'");
- }
- public function is_redis(){
- if($GLOBALS['distribution_cfg']['CACHE_TYPE']=="Rediscache"||$GLOBALS['distribution_cfg']['CACHE_CLIENT']!="")
- {
- return true;
- }else{
- return false;
- }
- }
- }//类定义结束
- ?>
|