mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
调试模式 关闭字段缓存 取消app类的日志初始化和缓存初始化 改为使用的时候自动初始化
This commit is contained in:
@@ -51,11 +51,6 @@ class App
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日志初始化
|
|
||||||
Log::init($config['log']);
|
|
||||||
// 缓存初始化
|
|
||||||
Cache::connect($config['cache']);
|
|
||||||
|
|
||||||
// 设置系统时区
|
// 设置系统时区
|
||||||
date_default_timezone_set($config['default_timezone']);
|
date_default_timezone_set($config['default_timezone']);
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ namespace think;
|
|||||||
|
|
||||||
class Cache
|
class Cache
|
||||||
{
|
{
|
||||||
public static $readTimes = 0;
|
protected static $instance = [];
|
||||||
public static $writeTimes = 0;
|
public static $readTimes = 0;
|
||||||
|
public static $writeTimes = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作句柄
|
* 操作句柄
|
||||||
@@ -31,15 +32,23 @@ class Cache
|
|||||||
*/
|
*/
|
||||||
public static function connect(array $options = [])
|
public static function connect(array $options = [])
|
||||||
{
|
{
|
||||||
$type = !empty($options['type']) ? $options['type'] : 'File';
|
$md5 = md5(serialize($options));
|
||||||
$class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type);
|
if (!isset(self::$instance[$md5])) {
|
||||||
unset($options['type']);
|
$type = !empty($options['type']) ? $options['type'] : 'File';
|
||||||
self::$handler = new $class($options);
|
$class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type);
|
||||||
|
unset($options['type']);
|
||||||
|
self::$instance[$md5] = new $class($options);
|
||||||
|
}
|
||||||
|
self::$handler = self::$instance[$md5];
|
||||||
return self::$handler;
|
return self::$handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function __callStatic($method, $params)
|
public static function __callStatic($method, $params)
|
||||||
{
|
{
|
||||||
|
if (is_null(self::$handler)) {
|
||||||
|
// 自动初始化缓存
|
||||||
|
self::connect(Config::get('cache'));
|
||||||
|
}
|
||||||
return call_user_func_array([self::$handler, $method], $params);
|
return call_user_func_array([self::$handler, $method], $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,10 @@ class Log
|
|||||||
*/
|
*/
|
||||||
public static function save()
|
public static function save()
|
||||||
{
|
{
|
||||||
self::$driver && self::$driver->save(self::$log);
|
if (is_null(self::$driver)) {
|
||||||
|
self::init(Config::get('log'));
|
||||||
|
}
|
||||||
|
self::$driver->save(self::$log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,8 +98,11 @@ class Log
|
|||||||
|
|
||||||
// 监听log_write
|
// 监听log_write
|
||||||
APP_HOOK && Hook::listen('log_write', $log);
|
APP_HOOK && Hook::listen('log_write', $log);
|
||||||
|
if (is_null(self::$driver)) {
|
||||||
|
self::init(Config::get('log'));
|
||||||
|
}
|
||||||
// 写入日志
|
// 写入日志
|
||||||
self::$driver && self::$driver->save($log);
|
self::$driver->save($log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1142,7 +1142,7 @@ class Model
|
|||||||
}
|
}
|
||||||
// 记录字段类型信息
|
// 记录字段类型信息
|
||||||
$this->fields['_type'] = $type;
|
$this->fields['_type'] = $type;
|
||||||
Cache::set($guid, $this->fields);
|
APP_DEBUG && Cache::set($guid, $this->fields);
|
||||||
$fields = $this->fields;
|
$fields = $this->fields;
|
||||||
} else {
|
} else {
|
||||||
$this->fields = $fields;
|
$this->fields = $fields;
|
||||||
|
|||||||
Reference in New Issue
Block a user