优化网站性能;

This commit is contained in:
2022-03-18 23:09:28 +08:00
parent d2cb402f71
commit 370a6cdc4d
6 changed files with 437 additions and 404 deletions

View File

@@ -1,6 +1,6 @@
<?php
return [
'\app\middleware\PermissionRecord',
'\app\middleware\AdminLog',
// '\app\middleware\PermissionRecord',
// '\app\middleware\AdminLog',
];

View File

@@ -36,7 +36,6 @@ function json_message($data = [], $code = 0, $msg = '')
$msg = $data;
$data = [];
}
} else if ($data instanceof Url) {
$data = [
'jump_to_url' => (string)$data

View File

@@ -5,6 +5,7 @@ namespace app\index\controller;
use app\model\Category;
use app\model\Post;
use app\model\PostCategory;
use think\facade\Cache;
use think\facade\Session;
use think\facade\View;
use think\Request;
@@ -18,6 +19,17 @@ class Index extends Common
*/
public function index()
{
$page_cache_key = md5($this->request->url());
$content = Cache::get($page_cache_key);
if (!empty($content)) {
return $content;
}
//
$sub_category = [];
$current_category = [];
@@ -52,7 +64,8 @@ class Index extends Common
$list_post = $model_post->paginate([
'url' => 'Index/index',
'query' => $this->request->get()
'query' => $this->request->get(),
'list_rows' => 10
]);
View::assign('current_category', $current_category);
@@ -60,7 +73,9 @@ class Index extends Common
View::assign('list_post', $list_post);
return View::fetch();
$content = View::fetch();
Cache::tag('page_cache')->set($page_cache_key, $content);
}

View File

@@ -20,7 +20,11 @@ class Category extends Base
[
'name' => 'category_type_list',
'field' => 'type'
]
],
[
'type' => 'tag',
'name' => 'page_cache'
],
];

View File

@@ -18,7 +18,11 @@ class Nav extends Base
'type' => 'key',
'name' => 'type_list',
'field' => 'type'
]
],
[
'type' => 'tag',
'name' => 'page_cache'
],
];
public static $statusName = [

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\model;
use app\common\model\Base;
use think\facade\Cache;
use think\facade\Request;
use think\Model;
@@ -13,10 +14,20 @@ use think\Paginator;
/**
* @mixin think\Model
*/
class Post extends Model
class Post extends Base
{
//
public static $autoClearCache = [
[
'name' => 'top_post'
],
[
'type' => 'tag',
'name' => 'page_cache'
],
];
public static $stausNameList = [
0 => '不发布',
1 => '发布'