mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进Cache类init方法
This commit is contained in:
@@ -23,12 +23,12 @@ class Cache
|
||||
/**
|
||||
* @var int 缓存读取次数
|
||||
*/
|
||||
public static $readTimes = 0;
|
||||
public static $readTimes = 0;
|
||||
|
||||
/**
|
||||
* @var int 缓存写入次数
|
||||
*/
|
||||
public static $writeTimes = 0;
|
||||
public static $writeTimes = 0;
|
||||
|
||||
/**
|
||||
* @var object 操作句柄
|
||||
@@ -46,17 +46,21 @@ class Cache
|
||||
{
|
||||
$type = !empty($options['type']) ? $options['type'] : 'File';
|
||||
|
||||
if (false === $name) $name = md5(serialize($options));
|
||||
if (false === $name) {
|
||||
$name = md5(serialize($options));
|
||||
}
|
||||
|
||||
if (true === $name || !isset(self::$instance[$name])) {
|
||||
$class = false === strpos($type, '\\') ?
|
||||
'\\think\\cache\\driver\\' . ucwords($type) :
|
||||
$type;
|
||||
'\\think\\cache\\driver\\' . ucwords($type) :
|
||||
$type;
|
||||
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ CACHE ] INIT ' . $type, 'info');
|
||||
|
||||
if (true === $name) return new $class($options);
|
||||
if (true === $name) {
|
||||
return new $class($options);
|
||||
}
|
||||
|
||||
self::$instance[$name] = new $class($options);
|
||||
}
|
||||
@@ -73,15 +77,15 @@ class Cache
|
||||
public static function init(array $options = [])
|
||||
{
|
||||
if (is_null(self::$handler)) {
|
||||
if (!empty($options)) {
|
||||
$connect = self::connect($options);
|
||||
} elseif ('complex' == Config::get('cache.type')) {
|
||||
$connect = self::connect(Config::get('cache.default'));
|
||||
if (empty($options) && 'complex' == Config::get('cache.type')) {
|
||||
$default = Config::get('cache.default');
|
||||
// 获取默认缓存配置,并连接
|
||||
$options = Config::get('cache.' . $default['type']) ?: Config::get('cache.default');
|
||||
} else {
|
||||
$connect = self::connect(Config::get('cache'));
|
||||
$options = !empty($options) ? $options : Config::get('cache');
|
||||
}
|
||||
|
||||
self::$handler = $connect;
|
||||
self::$handler = self::connect($options);
|
||||
}
|
||||
|
||||
return self::$handler;
|
||||
|
||||
Reference in New Issue
Block a user