| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: liu21st <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- // $Id$
- /**
- +------------------------------------------------------------------------------
- * 缓存管理类
- +------------------------------------------------------------------------------
- * @category Think
- * @package Think
- * @subpackage Util
- * @author liu21st <liu21st@gmail.com>
- * @version $Id$
- +------------------------------------------------------------------------------
- */
- class Cache extends Think
- {//类定义开始
- /**
- +----------------------------------------------------------
- * 是否连接
- +----------------------------------------------------------
- * @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 ;
- /**
- +----------------------------------------------------------
- * 连接缓存
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @param string $type 缓存类型
- * @param array $options 配置数组
- +----------------------------------------------------------
- * @return object
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- public function connect($type='',$options=array())
- {
- if(empty($type)) $type = C('DATA_CACHE_TYPE');
- $cachePath = dirname(__FILE__).'/Cache/';
- $cacheClass = 'Cache'.ucwords(strtolower(trim($type)));
- require_cache($cachePath.$cacheClass.'.class.php');
- if(class_exists($cacheClass))
- $cache = new $cacheClass($options);
- else
- throw_exception(L('_CACHE_TYPE_INVALID_').':'.$type);
- return $cache;
- }
- public function __get($name) {
- return $this->get($name);
- }
- public function __set($name,$value) {
- return $this->set($name,$value);
- }
- public function __unset($name) {
- $this->rm($name);
- }
- public function setOptions($name,$value) {
- $this->options[$name] = $value;
- }
- public function getOptions($name) {
- return $this->options[$name];
- }
- /**
- +----------------------------------------------------------
- * 取得缓存类实例
- +----------------------------------------------------------
- * @static
- * @access public
- +----------------------------------------------------------
- * @return mixed
- +----------------------------------------------------------
- */
- static function getInstance()
- {
- $param = func_get_args();
- return get_instance_of(__CLASS__,'connect',$param);
- }
- // 读取缓存次数
- public function Q($times='') {
- static $_times = 0;
- if(empty($times))
- return $_times;
- else
- $_times++;
- }
- // 写入缓存次数
- public function W($times='') {
- static $_times = 0;
- if(empty($times))
- return $_times;
- else
- $_times++;
- }
- }//类定义结束
- ?>
|