mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
优化网站缓存;
This commit is contained in:
@@ -43,15 +43,18 @@ trait AutoClearCache
|
||||
|
||||
$field = $cache_item['field'] ?? '';
|
||||
|
||||
|
||||
|
||||
$cache_key = $cache_item['name'] ?? '';
|
||||
|
||||
if (empty($cache_key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($field)) {
|
||||
if (!is_null($model->$field)) {
|
||||
$cache_key = $cache_key . '_' . $model->$field;
|
||||
$cache_key = $cache_key . '_' . $model->getAttr($field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,22 +18,22 @@ class Common extends BaseController
|
||||
parent::initialize();
|
||||
|
||||
|
||||
$list_nav_slide = Nav::where('type', 3)->cache('type_3_list')->order('sort asc')->where('status', 1)->select();
|
||||
$list_nav_slide = Nav::where('type', 3)->cache('type_list_3')->order('sort asc')->where('status', 1)->select();
|
||||
|
||||
View::assign('list_nav_slide', $list_nav_slide);
|
||||
|
||||
$list_nav_friend_url = Nav::where('type', 2)->cache('type_2_list')->order('sort asc')->where('status', 1)->select();
|
||||
$list_nav_friend_url = Nav::where('type', 2)->cache('type_list_2')->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_friend_url', $list_nav_friend_url);
|
||||
|
||||
$list_header_nav = Nav::where('type', 11)->order('sort asc')->where('status', 1)->select();
|
||||
$list_header_nav = Nav::where('type', 11)->cache('type_list_11')->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_header_nav', $list_header_nav);
|
||||
|
||||
$list_category_first_level = Category::where('level', 1)->where('status', 1)->where('type', 3)->order('sort asc')->select();
|
||||
$list_category_first_level = Category::where('level', 1)->where('status', 1)->where('type', 3)->cache('category_type_list_3')->order('sort asc')->select();
|
||||
View::assign('list_category_first_level', $list_category_first_level);
|
||||
$list_nav_more = Nav::where('type', 8)->order('sort asc')->where('status', 1)->select();
|
||||
$list_nav_more = Nav::where('type', 8)->cache('type_list_8')->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_more', $list_nav_more);
|
||||
|
||||
$top_posts = Post::where('is_top', 1)->limit(8)->where('type', 3)->select();
|
||||
$top_posts = Post::where('is_top', 1)->limit(8)->where('type', 3)->cache('top_post')->select();
|
||||
View::assign('top_posts', $top_posts);
|
||||
|
||||
$this->userHubLogin();
|
||||
|
||||
@@ -4,16 +4,26 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use app\common\model\Base;
|
||||
use think\facade\Config;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Category extends Model
|
||||
class Category extends Base
|
||||
{
|
||||
//
|
||||
|
||||
|
||||
public static $autoClearCache = [
|
||||
[
|
||||
'name' => 'category_type_list',
|
||||
'field' => 'type'
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
public static $allCategory = [];
|
||||
|
||||
|
||||
@@ -127,5 +137,4 @@ class Category extends Model
|
||||
->where('level', $this->getData('level'))
|
||||
->select();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ class Nav extends Base
|
||||
|
||||
public static $autoClearCache = [
|
||||
[
|
||||
'name' => 'type_3_list'
|
||||
'type' => 'key',
|
||||
'name' => 'type_list',
|
||||
'field' => 'type'
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Env;
|
||||
use think\facade\App;
|
||||
|
||||
@@ -94,6 +95,7 @@ return [
|
||||
'sql_explain' => false,
|
||||
// 是否需要断线重连
|
||||
'break_reconnect' => false,
|
||||
'fields_cache' => true
|
||||
],
|
||||
// 更多的数据库配置信息
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user