From 855c2c75da39964d75a6524a5230a010883975eb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 5 May 2016 16:32:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BCache=E7=B1=BB=20=E5=8F=8A=20?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=20=E6=94=B9=E8=BF=9BConnection=E7=B1=BB?= =?UTF-8?q?=E5=8F=8A=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 91 ++++++++-- library/think/cache/driver/Apc.php | 27 +-- library/think/cache/driver/CacheInterface.php | 50 ------ library/think/cache/driver/Db.php | 165 ------------------ library/think/cache/driver/File.php | 23 +-- library/think/cache/driver/Lite.php | 13 +- library/think/cache/driver/Memcache.php | 22 +-- library/think/cache/driver/Memcached.php | 22 +-- library/think/cache/driver/Redis.php | 22 +-- library/think/cache/driver/Sae.php | 36 +--- library/think/cache/driver/Secache.php | 27 +-- library/think/cache/driver/Sqlite.php | 6 - library/think/cache/driver/Test.php | 2 +- library/think/cache/driver/Wincache.php | 23 +-- library/think/cache/driver/Xcache.php | 23 +-- library/think/db/Connection.php | 34 +++- library/think/db/ConnectionInterface.php | 47 ----- library/think/db/connector/Mysql.php | 8 +- library/think/db/connector/Oracle.php | 8 +- library/think/db/connector/Pgsql.php | 8 +- library/think/db/connector/Sqlite.php | 8 +- library/think/db/connector/Sqlsrv.php | 8 +- library/think/log/driver/File.php | 2 +- library/think/log/driver/LogInterface.php | 25 --- library/think/log/driver/Sae.php | 2 +- library/think/log/driver/Socket.php | 2 +- library/think/log/driver/Test.php | 2 +- library/think/log/driver/Trace.php | 2 +- library/think/view/driver/Php.php | 2 +- library/think/view/driver/Think.php | 2 +- library/think/view/driver/ViewInterface.php | 34 ---- 31 files changed, 147 insertions(+), 599 deletions(-) delete mode 100644 library/think/cache/driver/CacheInterface.php delete mode 100644 library/think/cache/driver/Db.php delete mode 100644 library/think/db/ConnectionInterface.php delete mode 100644 library/think/log/driver/LogInterface.php delete mode 100644 library/think/view/driver/ViewInterface.php diff --git a/library/think/Cache.php b/library/think/Cache.php index 333db049..19ca36d4 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -11,15 +11,6 @@ namespace think; -/** - * Class Cache - * - * @package think - * @method static mixed get() get(string $name) - * @method static bool set() set(string $name, mixed $value, mixed $expire = null) - * @method static bool rm() rm(string $name, bool $expire = false) - * @method static bool clear() clear() - */ class Cache { protected static $instance = []; @@ -37,29 +28,93 @@ class Cache * 连接缓存 * @access public * @param array $options 配置数组 + * @param bool|string $name 缓存连接标识 true 强制重新连接 * @return object */ - public static function connect(array $options = []) + public static function connect(array $options = [], $name = false) { - $md5 = md5(serialize($options)); - if (!isset(self::$instance[$md5])) { - $type = !empty($options['type']) ? $options['type'] : 'File'; + $type = !empty($options['type']) ? $options['type'] : 'File'; + if (false === $name) { + $name = $type; + } + + if (true === $name || !isset(self::$instance[$name])) { $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type); - unset($options['type']); - self::$instance[$md5] = new $class($options); + // 记录初始化信息 APP_DEBUG && Log::record('[ CACHE ] INIT ' . $type . ':' . var_export($options, true), 'info'); + if (true === $name) { + return new $class($options); + } else { + self::$instance[$name] = new $class($options); + } } - self::$handler = self::$instance[$md5]; + self::$handler = self::$instance[$name]; return self::$handler; } - public static function __callStatic($method, $params) + /** + * 自动初始化缓存 + * @access public + * @return void + */ + public static function init() { if (is_null(self::$handler)) { // 自动初始化缓存 self::connect(Config::get('cache')); } - return call_user_func_array([self::$handler, $method], $params); } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存标识 + * @return mixed + */ + public static function get($name) + { + self::init(); + self::$readTimes++; + return self::$hander->get($name); + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存标识 + * @param mixed $value 存储数据 + * @param int|null $expire 有效时间 0为永久 + * @return boolean + */ + public static function set($name, $value, $expire = null) + { + self::init(); + self::$writeTimes++; + return self::$hander->set($name, $value, $expire); + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存标识 + * @return boolean + */ + public static function rm($name) + { + self::init(); + return self::$hander->rm($name); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public static function clear() + { + self::init(); + return self::$hander->clear(); + } + } diff --git a/library/think/cache/driver/Apc.php b/library/think/cache/driver/Apc.php index 05ee8a29..ebe163cc 100644 --- a/library/think/cache/driver/Apc.php +++ b/library/think/cache/driver/Apc.php @@ -18,9 +18,8 @@ use think\Exception; * Apc缓存驱动 * @author liu21st */ -class Apc implements CacheInterface +class Apc { - protected $options = [ 'expire' => 0, 'prefix' => '', @@ -53,7 +52,6 @@ class Apc implements CacheInterface */ public function get($name) { - Cache::$readTimes++; return apc_fetch($this->options['prefix'] . $name); } @@ -67,32 +65,11 @@ class Apc implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; - if ($result = apc_store($name, $value, $expire)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue = apc_fetch('__info__'); - if (!$queue) { - $queue = []; - } - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - apc_delete($key); - } - apc_store('__info__', $queue); - } - } - return $result; + return apc_store($name, $value, $expire); } /** diff --git a/library/think/cache/driver/CacheInterface.php b/library/think/cache/driver/CacheInterface.php deleted file mode 100644 index 93716c76..00000000 --- a/library/think/cache/driver/CacheInterface.php +++ /dev/null @@ -1,50 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\cache\driver; - -interface CacheInterface -{ - - /** - * 读取缓存 - * @access public - * @param string $name 缓存变量名 - * @return mixed - */ - public function get($name); - - /** - * 写入缓存 - * @access public - * @param string $name 缓存变量名 - * @param mixed $value 存储数据 - * @param int $expire 有效时间 0为永久 - * @return boolean - */ - public function set($name, $value, $expire = null); - - /** - * 删除缓存 - * @access public - * @param string $name 缓存变量名 - * @return boolean - */ - public function rm($name); - - /** - * 清除缓存 - * @access public - * @return boolean - */ - public function clear(); - -} diff --git a/library/think/cache/driver/Db.php b/library/think/cache/driver/Db.php deleted file mode 100644 index e8bc9283..00000000 --- a/library/think/cache/driver/Db.php +++ /dev/null @@ -1,165 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\cache\driver; - -use think\Cache; - -/** - * 数据库方式缓存驱动 - * CREATE TABLE think_cache ( - * cachekey varchar(255) NOT NULL, - * expire int(11) NOT NULL, - * data blob, - * datacrc int(32), - * UNIQUE KEY `cachekey` (`cachekey`) - * ); - * @author liu21st - */ -class Db implements CacheInterface -{ - - protected $handler = null; - protected $options = [ - 'type' => '', - 'dsn' => '', - 'hostname' => '', - 'hostport' => '', - 'username' => '', - 'password' => '', - 'database' => '', - 'charset' => '', - 'table' => '', - 'prefix' => '', - 'expire' => 0, - 'length' => 0, - ]; - - /** - * 架构函数 - * @param array $options 缓存参数 - * @access public - */ - public function __construct($options = []) - { - if (!empty($options)) { - $this->options = array_merge($this->options, $options); - } - $this->handler = \think\Db::connect((!empty($this->options['hostname']) || !empty($this->options['dsn'])) ? $this->options : []); - } - - /** - * 读取缓存 - * @access public - * @param string $name 缓存变量名 - * @return mixed - */ - public function get($name) - { - Cache::$readTimes++; - $name = $this->options['prefix'] . addslashes($name); - $result = $this->handler->query('SELECT `data`,`datacrc` FROM `' . $this->options['table'] . '` WHERE `cachekey`=\'' . $name . '\' AND (`expire` =0 OR `expire`>' . time() . ') LIMIT 0,1'); - if (false !== $result) { - $result = $result[0]; - $content = $result['data']; - if (function_exists('gzcompress')) { - //启用数据压缩 - $content = gzuncompress($content); - } - $content = unserialize($content); - return $content; - } else { - return false; - } - } - - /** - * 写入缓存 - * @access public - * @param string $name 缓存变量名 - * @param mixed $value 存储数据 - * @param integer $expire 有效时间(秒) - * @return boolean - */ - public function set($name, $value, $expire = null) - { - Cache::$writeTimes++; - $data = serialize($value); - $name = $this->options['prefix'] . addslashes($name); - if (function_exists('gzcompress')) { - //数据压缩 - $data = gzcompress($data, 3); - } - if (is_null($expire)) { - $expire = $this->options['expire']; - } - $expire = (0 == $expire) ? 0 : (time() + $expire); //缓存有效期为0表示永久缓存 - $result = $this->handler->query('select `cachekey` from `' . $this->options['table'] . '` where `cachekey`=\'' . $name . '\' limit 0,1'); - if (!empty($result)) { - //更新记录 - $result = $this->handler->execute('UPDATE ' . $this->options['table'] . ' SET data=\'' . $data . '\' ,expire=' . $expire . ' WHERE `cachekey`=\'' . $name . '\''); - } else { - //新增记录 - $result = $this->handler->execute('INSERT INTO ' . $this->options['table'] . ' (`cachekey`,`data`,`expire`) VALUES (\'' . $name . '\',\'' . $data . '\',' . $expire . ')'); - } - if ($result) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $result = $this->handler->query('SELECT `data`,`datacrc` FROM `' . $this->options['table'] . '` WHERE `cachekey`=\'__info__\' AND `expire` =0 LIMIT 0,1'); - $queue = xcache_get('__info__'); - if (!$result) { - $this->handler->execute('INSERT INTO ' . $this->options['table'] . ' (`cachekey`,`data`,`expire`) VALUES (\'__info__\',\'\',0)'); - $queue = []; - } else { - $queue = unserialize($result[0]['data']); - } - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - $this->handler->execute('DELETE FROM `' . $this->options['table'] . '` WHERE `cachekey`=\'' . $key . '\''); - } - $this->handler->execute('UPDATE ' . $this->options['table'] . ' SET data=\'' . serialize($queue) . '\' ,expire=0 WHERE `cachekey`=\'__info__\''); - xcache_set('__info__', $queue); - } - return true; - } else { - return false; - } - } - - /** - * 删除缓存 - * @access public - * @param string $name 缓存变量名 - * @return boolean - */ - public function rm($name) - { - $name = $this->options['prefix'] . addslashes($name); - return $this->handler->execute('DELETE FROM `' . $this->options['table'] . '` WHERE `cachekey`=\'' . $name . '\''); - } - - /** - * 清除缓存 - * @access public - * @return boolean - */ - public function clear() - { - return $this->handler->execute('TRUNCATE TABLE `' . $this->options['table'] . '`'); - } - -} diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index 48fd2327..2c0ddff1 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -17,7 +17,7 @@ use think\Cache; * 文件类型缓存类 * @author liu21st */ -class File implements CacheInterface +class File { protected $options = [ @@ -98,7 +98,6 @@ class File implements CacheInterface if (!is_file($filename)) { return false; } - Cache::$readTimes++; $content = file_get_contents($filename); if (false !== $content) { $expire = (int) substr($content, 8, 12); @@ -129,7 +128,6 @@ class File implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } @@ -142,25 +140,6 @@ class File implements CacheInterface $data = ""; $result = file_put_contents($filename, $data); if ($result) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue_file = dirname($filename) . '/__info__.php'; - $queue = unserialize(file_get_contents($queue_file)); - if (!$queue) { - $queue = []; - } - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - $this->unlink($this->filename($key)); - } - file_put_contents($queue_file, serialize($queue)); - } clearstatcache(); return true; } else { diff --git a/library/think/cache/driver/Lite.php b/library/think/cache/driver/Lite.php index 2967b586..c2095368 100644 --- a/library/think/cache/driver/Lite.php +++ b/library/think/cache/driver/Lite.php @@ -17,7 +17,7 @@ use think\Cache; * 文件类型缓存类 * @author liu21st */ -class Lite implements CacheInterface +class Lite { protected $options = [ 'prefix' => '', @@ -61,7 +61,6 @@ class Lite implements CacheInterface */ public function get($name) { - Cache::$readTimes++; $filename = $this->filename($name); if (is_file($filename)) { // 判断是否过期 @@ -87,7 +86,6 @@ class Lite implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } @@ -96,14 +94,7 @@ class Lite implements CacheInterface $expire = 10 * 365 * 24 * 3600; } $filename = $this->filename($name); - // 缓存数据 - /* - $dir = dirname($filename); - // 目录不存在则创建 - if (!is_dir($dir)) - mkdir($dir,0755,true); - */ - $ret = file_put_contents($filename, ("handler->get($this->options['prefix'] . $name); } @@ -79,30 +78,11 @@ class Memcache implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; if ($this->handler->set($name, $value, 0, $expire)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue = $this->handler->get('__info__'); - if (!$queue) { - $queue = []; - } - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - $this->handler->delete($key); - } - $this->handler->set('__info__', $queue); - } return true; } return false; diff --git a/library/think/cache/driver/Memcached.php b/library/think/cache/driver/Memcached.php index 16631a39..f82500f5 100644 --- a/library/think/cache/driver/Memcached.php +++ b/library/think/cache/driver/Memcached.php @@ -14,7 +14,7 @@ namespace think\cache\driver; use think\Cache; use think\Exception; -class Memcached implements CacheInterface +class Memcached { protected $handler = null; protected $options = [ @@ -66,7 +66,6 @@ class Memcached implements CacheInterface */ public function get($name) { - Cache::$readTimes++; return $this->handler->get($this->options['prefix'] . $name); } @@ -80,31 +79,12 @@ class Memcached implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; $expire = 0 == $expire ? 0 : time() + $expire; if ($this->handler->set($name, $value, $expire)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue = $this->handler->get('__info__'); - if (!$queue) { - $queue = []; - } - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - $this->handler->delete($key); - } - $this->handler->set('__info__', $queue); - } return true; } return false; diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index 999122c6..6ae0f1da 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -19,7 +19,7 @@ use think\Exception; * 要求安装phpredis扩展:https://github.com/nicolasff/phpredis * @author 尘缘 <130775@qq.com> */ -class Redis implements CacheInterface +class Redis { protected $handler = null; protected $options = [ @@ -64,7 +64,6 @@ class Redis implements CacheInterface */ public function get($name) { - Cache::$readTimes++; $value = $this->handler->get($this->options['prefix'] . $name); $jsonData = json_decode($value, true); // 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson @@ -81,7 +80,6 @@ class Redis implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } @@ -93,24 +91,6 @@ class Redis implements CacheInterface } else { $result = $this->handler->set($name, $value); } - if ($result && $this->options['length'] > 0) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue = $this->handler->get('__info__'); - $queue = explode(',', $queue); - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - $this->handler->delete($key); - } - $this->handler->set('__info__', implode(',', $queue)); - } - } return $result; } diff --git a/library/think/cache/driver/Sae.php b/library/think/cache/driver/Sae.php index cb817b28..4bead286 100644 --- a/library/think/cache/driver/Sae.php +++ b/library/think/cache/driver/Sae.php @@ -18,7 +18,7 @@ use think\Exception; * SAE Memcache缓存驱动 * @author liu21st */ -class Sae implements CacheInterface +class Sae { protected $handler = null; protected $options = [ @@ -58,7 +58,6 @@ class Sae implements CacheInterface */ public function get($name) { - Cache::$readTimes++; return $this->handler->get($_SERVER['HTTP_APPVERSION'] . '/' . $this->options['prefix'] . $name); } @@ -72,16 +71,11 @@ class Sae implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; if ($this->handler->set($_SERVER['HTTP_APPVERSION'] . '/' . $name, $value, 0, $expire)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $this->queue($name); - } return true; } return false; @@ -126,32 +120,4 @@ class Sae implements CacheInterface return $kv; } - /** - * 队列缓存 - * @access protected - * @param string $key 队列名 - * @return mixed - */ - //[sae] 下重写queque队列缓存方法 - protected function queue($key) - { - $queue_name = isset($this->options['queue_name']) ? $this->options['queue_name'] : 'think_queue'; - $kv = $this->getKv(); - $value = $kv->get($queue_name); - if (!$value) { - $value = []; - } - // 进列 - if (false === array_search($key, $value)) { - array_push($value, $key); - } - - if (count($value) > $this->options['length']) { - // 出列 - $key = array_shift($value); - // 删除缓存 - $this->rm($key); - } - return $kv->set($queue_name, $value); - } } diff --git a/library/think/cache/driver/Secache.php b/library/think/cache/driver/Secache.php index 950641be..13613bfe 100644 --- a/library/think/cache/driver/Secache.php +++ b/library/think/cache/driver/Secache.php @@ -17,9 +17,8 @@ use think\Cache; * Secache缓存驱动 * @author liu21st */ -class Secache implements CacheInterface +class Secache { - protected $handler = null; protected $options = [ 'project' => '', @@ -55,7 +54,6 @@ class Secache implements CacheInterface */ public function get($name) { - Cache::$readTimes++; $name = $this->options['prefix'] . $name; $key = md5($name); $this->handler->fetch($key, $return); @@ -72,30 +70,9 @@ class Secache implements CacheInterface */ public function set($name, $value) { - Cache::$writeTimes++; $name = $this->options['prefix'] . $name; $key = md5($name); - if ($result = $this->handler->store($key, $value)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue = $this->handler->fetch(md5('__info__')); - if (!$queue) { - $queue = []; - } - if (false === array_search($key, $queue)) { - array_push($queue, $key); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - $this->handler->delete($key); - } - $this->handler->store(md5('__info__'), $queue); - } - } - return $result; + return $this->handler->store($key, $value); } /** diff --git a/library/think/cache/driver/Sqlite.php b/library/think/cache/driver/Sqlite.php index 57132722..89a24e96 100644 --- a/library/think/cache/driver/Sqlite.php +++ b/library/think/cache/driver/Sqlite.php @@ -56,7 +56,6 @@ class Sqlite implements CacheInterface */ public function get($name) { - Cache::$readTimes++; $name = $this->options['prefix'] . sqlite_escape_string($name); $sql = 'SELECT value FROM ' . $this->options['table'] . ' WHERE var=\'' . $name . '\' AND (expire=0 OR expire >' . time() . ') LIMIT 1'; $result = sqlite_query($this->handler, $sql); @@ -81,7 +80,6 @@ class Sqlite implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; $name = $this->options['prefix'] . sqlite_escape_string($name); $value = sqlite_escape_string(serialize($value)); if (is_null($expire)) { @@ -94,10 +92,6 @@ class Sqlite implements CacheInterface } $sql = 'REPLACE INTO ' . $this->options['table'] . ' (var, value,expire) VALUES (\'' . $name . '\', \'' . $value . '\', \'' . $expire . '\')'; if (sqlite_query($this->handler, $sql)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $this->queue($name); - } return true; } return false; diff --git a/library/think/cache/driver/Test.php b/library/think/cache/driver/Test.php index ee26da00..95ea31e1 100644 --- a/library/think/cache/driver/Test.php +++ b/library/think/cache/driver/Test.php @@ -17,7 +17,7 @@ use think\Cache; * 测试缓存类 * @author liu21st */ -class Test implements CacheInterface +class Test { /** diff --git a/library/think/cache/driver/Wincache.php b/library/think/cache/driver/Wincache.php index 18858a19..e77b53a2 100644 --- a/library/think/cache/driver/Wincache.php +++ b/library/think/cache/driver/Wincache.php @@ -18,9 +18,8 @@ use think\Exception; * Wincache缓存驱动 * @author liu21st */ -class Wincache implements CacheInterface +class Wincache { - protected $options = [ 'prefix' => '', 'expire' => 0, @@ -51,7 +50,6 @@ class Wincache implements CacheInterface */ public function get($name) { - Cache::$readTimes++; $name = $this->options['prefix'] . $name; return wincache_ucache_exists($name) ? wincache_ucache_get($name) : false; } @@ -66,30 +64,11 @@ class Wincache implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; if (wincache_ucache_set($name, $value, $expire)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue = wincache_ucache_get('__info__'); - if (!$queue) { - $queue = []; - } - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - wincache_ucache_delete($key); - } - wincache_ucache_set('__info__', $queue); - } return true; } return false; diff --git a/library/think/cache/driver/Xcache.php b/library/think/cache/driver/Xcache.php index b128fe3c..a529bed3 100644 --- a/library/think/cache/driver/Xcache.php +++ b/library/think/cache/driver/Xcache.php @@ -18,9 +18,8 @@ use think\Exception; * Xcache缓存驱动 * @author liu21st */ -class Xcache implements CacheInterface +class Xcache { - protected $options = [ 'prefix' => '', 'expire' => 0, @@ -50,7 +49,6 @@ class Xcache implements CacheInterface */ public function get($name) { - Cache::$readTimes++; $name = $this->options['prefix'] . $name; if (xcache_isset($name)) { return xcache_get($name); @@ -68,30 +66,11 @@ class Xcache implements CacheInterface */ public function set($name, $value, $expire = null) { - Cache::$writeTimes++; if (is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; if (xcache_set($name, $value, $expire)) { - if ($this->options['length'] > 0) { - // 记录缓存队列 - $queue = xcache_get('__info__'); - if (!$queue) { - $queue = []; - } - if (false === array_search($name, $queue)) { - array_push($queue, $name); - } - - if (count($queue) > $this->options['length']) { - // 出列 - $key = array_shift($queue); - // 删除缓存 - xcache_unset($key); - } - xcache_set('__info__', $queue); - } return true; } return false; diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index e225e2bc..96767870 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -21,7 +21,7 @@ use think\exception\DbBindParamException; use think\exception\PDOException; use think\Log; -abstract class Connection implements ConnectionInterface +abstract class Connection { // PDO操作实例 protected $PDOStatement; @@ -124,6 +124,38 @@ abstract class Connection implements ConnectionInterface return call_user_func_array([$this->query, $method], $args); } + /** + * 解析pdo连接的dsn信息 + * @access protected + * @param array $config 连接信息 + * @return string + */ + abstract protected function parseDsn($config); + + /** + * 取得数据表的字段信息 + * @access public + * @param string $tableName + * @return array + */ + abstract public function getFields($tableName); + + /** + * 取得数据库的表信息 + * @access public + * @param string $dbName + * @return array + */ + abstract public function getTables($dbName); + + /** + * SQL性能分析 + * @access protected + * @param string $sql + * @return array + */ + abstract protected function getExplain($sql); + /** * 对返数据表字段信息进行大小写转换出来 * @access public diff --git a/library/think/db/ConnectionInterface.php b/library/think/db/ConnectionInterface.php deleted file mode 100644 index f7930fe4..00000000 --- a/library/think/db/ConnectionInterface.php +++ /dev/null @@ -1,47 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\db; - -interface ConnectionInterface -{ - /** - * 解析pdo连接的dsn信息 - * @access public - * @param array $config 连接信息 - * @return string - */ - public function parseDsn($config); - - /** - * 取得数据表的字段信息 - * @access public - * @param string $tableName - * @return array - */ - public function getFields($tableName); - - /** - * 取得数据库的表信息 - * @access public - * @param string $dbName - * @return array - */ - public function getTables($dbName); - - /** - * SQL性能分析 - * @access protected - * @param string $sql - * @return array - */ - public function getExplain($sql); -} diff --git a/library/think/db/connector/Mysql.php b/library/think/db/connector/Mysql.php index 31f469d0..66b16a78 100644 --- a/library/think/db/connector/Mysql.php +++ b/library/think/db/connector/Mysql.php @@ -22,11 +22,11 @@ class Mysql extends Connection /** * 解析pdo连接的dsn信息 - * @access public + * @access protected * @param array $config 连接信息 * @return string */ - public function parseDsn($config) + protected function parseDsn($config) { $dsn = 'mysql:dbname=' . $config['database'] . ';host=' . $config['hostname']; if (!empty($config['hostport'])) { @@ -91,11 +91,11 @@ class Mysql extends Connection /** * SQL性能分析 - * @access public + * @access protected * @param string $sql * @return array */ - public function getExplain($sql) + protected function getExplain($sql) { $pdo = $this->linkID->query("EXPLAIN " . $sql); $result = $pdo->fetch(\PDO::FETCH_ASSOC); diff --git a/library/think/db/connector/Oracle.php b/library/think/db/connector/Oracle.php index f0398307..87ceaf8b 100644 --- a/library/think/db/connector/Oracle.php +++ b/library/think/db/connector/Oracle.php @@ -24,11 +24,11 @@ class Oracle extends Connection /** * 解析pdo连接的dsn信息 - * @access public + * @access protected * @param array $config 连接信息 * @return string */ - public function parseDsn($config) + protected function parseDsn($config) { $dsn = 'oci:dbname='; if (!empty($config['hostname'])) { @@ -139,11 +139,11 @@ class Oracle extends Connection /** * SQL性能分析 - * @access public + * @access protected * @param string $sql * @return array */ - public function getExplain($sql) + protected function getExplain($sql) { return []; } diff --git a/library/think/db/connector/Pgsql.php b/library/think/db/connector/Pgsql.php index d58ddbc1..03406efe 100644 --- a/library/think/db/connector/Pgsql.php +++ b/library/think/db/connector/Pgsql.php @@ -21,11 +21,11 @@ class Pgsql extends Connection /** * 解析pdo连接的dsn信息 - * @access public + * @access protected * @param array $config 连接信息 * @return string */ - public function parseDsn($config) + protected function parseDsn($config) { $dsn = 'pgsql:dbname=' . $config['database'] . ';host=' . $config['hostname']; if (!empty($config['hostport'])) { @@ -79,11 +79,11 @@ class Pgsql extends Connection /** * SQL性能分析 - * @access public + * @access protected * @param string $sql * @return array */ - public function getExplain($sql) + protected function getExplain($sql) { return []; } diff --git a/library/think/db/connector/Sqlite.php b/library/think/db/connector/Sqlite.php index 4984be0d..74ecc40e 100644 --- a/library/think/db/connector/Sqlite.php +++ b/library/think/db/connector/Sqlite.php @@ -21,11 +21,11 @@ class Sqlite extends Connection /** * 解析pdo连接的dsn信息 - * @access public + * @access protected * @param array $config 连接信息 * @return string */ - public function parseDsn($config) + protected function parseDsn($config) { $dsn = 'sqlite:' . $config['database']; return $dsn; @@ -78,11 +78,11 @@ class Sqlite extends Connection /** * SQL性能分析 - * @access public + * @access protected * @param string $sql * @return array */ - public function getExplain($sql) + protected function getExplain($sql) { return []; } diff --git a/library/think/db/connector/Sqlsrv.php b/library/think/db/connector/Sqlsrv.php index 4044181c..4d42ac1c 100644 --- a/library/think/db/connector/Sqlsrv.php +++ b/library/think/db/connector/Sqlsrv.php @@ -29,11 +29,11 @@ class Sqlsrv extends Connection /** * 解析pdo连接的dsn信息 - * @access public + * @access protected * @param array $config 连接信息 * @return string */ - public function parseDsn($config) + protected function parseDsn($config) { $dsn = 'sqlsrv:Database=' . $config['database'] . ';Server=' . $config['hostname']; if (!empty($config['hostport'])) { @@ -96,11 +96,11 @@ class Sqlsrv extends Connection /** * SQL性能分析 - * @access public + * @access protected * @param string $sql * @return array */ - public function getExplain($sql) + protected function getExplain($sql) { return []; } diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index 6fa7ce5e..b3fa9c42 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -13,7 +13,7 @@ namespace think\log\driver; /** * 本地化调试输出到文件 */ -class File implements LogInterface +class File { protected $config = [ 'time_format' => ' c ', diff --git a/library/think/log/driver/LogInterface.php b/library/think/log/driver/LogInterface.php deleted file mode 100644 index 7f394f64..00000000 --- a/library/think/log/driver/LogInterface.php +++ /dev/null @@ -1,25 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\log\driver; - -interface LogInterface -{ - - /** - * 日志写入接口 - * @access public - * @param array $log 日志信息 - * @return bool - */ - public function save(array $log = []); - -} diff --git a/library/think/log/driver/Sae.php b/library/think/log/driver/Sae.php index 3a8c37a0..7f3c3349 100644 --- a/library/think/log/driver/Sae.php +++ b/library/think/log/driver/Sae.php @@ -13,7 +13,7 @@ namespace think\log\driver; /** * 调试输出到SAE */ -class Sae implements LogInterface +class Sae { protected $config = [ 'log_time_format' => ' c ', diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index d3950a4d..6a5e87f7 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -5,7 +5,7 @@ */ namespace think\log\driver; -class Socket implements LogInterface +class Socket { public $port = 1116; //SocketLog 服务的http的端口号 diff --git a/library/think/log/driver/Test.php b/library/think/log/driver/Test.php index fdd1b118..e367ca3c 100644 --- a/library/think/log/driver/Test.php +++ b/library/think/log/driver/Test.php @@ -13,7 +13,7 @@ namespace think\log\driver; /** * 模拟测试输出 */ -class Test implements LogInterface +class Test { /** * 日志写入接口 diff --git a/library/think/log/driver/Trace.php b/library/think/log/driver/Trace.php index dc83acf8..d40f1071 100644 --- a/library/think/log/driver/Trace.php +++ b/library/think/log/driver/Trace.php @@ -16,7 +16,7 @@ use think\Debug; /** * 页面Trace调试 */ -class Trace implements LogInterface +class Trace { protected $config = [ 'trace_file' => '', diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 4fcbf2ac..fab8d688 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -13,7 +13,7 @@ namespace think\view\driver; use think\Exception; use think\Log; -class Php implements ViewInterface +class Php { // 模板引擎参数 protected $config = [ diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index e95d15b2..f06406c8 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -14,7 +14,7 @@ use think\Exception; use think\Log; use think\Template; -class Think implements ViewInterface +class Think { // 模板引擎实例 private $template = null; diff --git a/library/think/view/driver/ViewInterface.php b/library/think/view/driver/ViewInterface.php deleted file mode 100644 index ffe1da71..00000000 --- a/library/think/view/driver/ViewInterface.php +++ /dev/null @@ -1,34 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\view\driver; - -interface ViewInterface -{ - /** - * 渲染模板文件 - * @access public - * @param string $template 模板文件 - * @param array $data 模板变量 - * @return void - */ - public function fetch($template, $data = []); - - /** - * 渲染模板内容 - * @access public - * @param string $content 模板内容 - * @param array $data 模板变量 - * @return void - */ - public function display($content, $data = []); - -}