国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

thinkphp核心源碼注釋|Cache.class.php

2019-11-11 02:33:02
字體:
來源:轉載
供稿:網友
<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: liu21st <liu21st@Gmail.com>// +----------------------------------------------------------------------namespace Think;/** * 緩存管理類 */class Cache { // 緩存類應用層 /** * 操作句柄 * @var string * @access PRotected */ protected $handler ; /** * 緩存連接參數 * @var integer * @access protected */ protected $options = array(); /** * 連接緩存 * @access public * @param string $type 緩存類型 * @param array $options 配置數組 * @return object */ // 初始化緩存 public function connect($type='',$options=array()) { if(empty($type)) $type = C('DATA_CACHE_TYPE'); $class = strpos($type,'//')? $type : 'Think//Cache//Driver//'.ucWords(strtolower($type)); if(class_exists($class)) $cache = new $class($options); else E(L('_CACHE_TYPE_INVALID_').':'.$type); return $cache; } /** * 取得緩存類實例 * @static * @access public * @return mixed */ // 單例模式 返回其 實例化的 cache 類 然后在具體實例化 緩存對象 static function getInstance($type='',$options=array()) { static $_instance = array(); $guid = $type.to_guid_string($options); if(!isset($_instance[$guid])){ $obj = new Cache(); $_instance[$guid] = $obj->connect($type,$options); } return $_instance[$guid]; } // 所有的 的都是一個偽函數, 具體在實例化中的一個操作 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]; } /** * 隊列緩存 * @access protected * @param string $key 隊列名 * @return mixed */ // 隊列緩存就是一個數組的操作而已 protected function queue($key) { static $_handler = array( 'file' => array('F','F'), 'xcache'=> array('xcache_get','xcache_set'), 'apc' => array('apc_fetch','apc_store'), ); $queue = isset($this->options['queue'])?$this->options['queue']:'file'; $fun = isset($_handler[$queue])?$_handler[$queue]:$_handler['file']; $queue_name = isset($this->options['queue_name'])?$this->options['queue_name']:'think_queue'; $value = $fun[0]($queue_name); if(!$value) { $value = array(); } // 進列 if(false===array_search($key, $value)) array_push($value,$key); if(count($value) > $this->options['length']) { // 出列 $key = array_shift($value); // 刪除緩存 $this->rm($key); if(APP_DEBUG){ //調試模式下,記錄出列次數 N($queue_name.'_out_times',1); } } return $fun[1]($queue_name,$value); } // 魔術方法調用 public function __call($method,$args){ //調用緩存類型自己的方法 if(method_exists($this->handler, $method)){ return call_user_func_array(array($this->handler,$method), $args); }else{ E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); return; } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定边县| 公主岭市| 广水市| 偏关县| 桦甸市| 交口县| 汽车| 佳木斯市| 远安县| 长垣县| 兴业县| 珲春市| 襄樊市| 凤城市| 夏邑县| 金寨县| 印江| 惠州市| 万荣县| 韩城市| 乌拉特前旗| 崇阳县| 东兰县| 黄龙县| 和平县| 上饶市| 连平县| 胶州市| 峡江县| 绵阳市| 汨罗市| 平塘县| 招远市| 房产| 昌邑市| 弥勒县| 监利县| 商南县| 朔州市| 都兰县| 革吉县|