完成自动缓存和缓存清理;

This commit is contained in:
2022-02-13 12:44:17 +08:00
parent bc828f73e0
commit c4ac0764b9
5 changed files with 9 additions and 6 deletions

View File

@@ -57,6 +57,7 @@ function get_system_config($name = '', $default = '')
try {
$list = SystemConfig::column('value', 'name');
Cache::set('system_config',$list);
} catch (\Throwable $th) {
return $default;
}

View File

@@ -1,9 +1,10 @@
<?php
namespace app\common\model;
use app\common\traits\AutoClearCache;
use think\Model;
class Base extends Model
{
// use AutoClearCache;
use AutoClearCache;
}

View File

@@ -39,11 +39,11 @@ trait AutoClearCache
{
foreach (static::$autoClearCache as $cache_item) {
$type = $cache_item['type'] ?: 'key';
$type = $cache_item['type'] ?? 'key';
$field = $cache_item['field'] ?: '';
$field = $cache_item['field'] ?? '';
$cache_key = $cache_item['name'] ?: '';
$cache_key = $cache_item['name'] ?? '';
if (empty($cache_key)) {
continue;
@@ -56,7 +56,7 @@ trait AutoClearCache
}
if ($type == 'key') {
Cache::delete($type);
Cache::delete($cache_key);
} else {
Cache::tag($cache_key)->clear();
}

View File

@@ -17,6 +17,7 @@ class Common extends BaseController
{
parent::initialize();
$list_nav_slide = Nav::where('type', 3)->cache('type_3_list')->order('sort asc')->where('status', 1)->select();
View::assign('list_nav_slide', $list_nav_slide);

View File

@@ -12,5 +12,5 @@ return [
// 页面Trace调试
// \think\middleware\TraceDebug::class,
// '\app\\middleware\ConfigInit'
'\app\\middleware\ConfigInit'
];