mirror of
https://gitee.com/ulthon/layui-ul.git
synced 2026-07-08 05:12:48 +08:00
优化缓存,增加头像列表
This commit is contained in:
@@ -14,6 +14,14 @@ use think\Request;
|
||||
|
||||
class Post extends Common
|
||||
{
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
ModelPost::quickSelect(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
|
||||
@@ -20,7 +20,9 @@ class Index extends Common
|
||||
{
|
||||
//
|
||||
|
||||
$list_post = Post::where('status', 1)->order('sort desc')->select();
|
||||
|
||||
|
||||
$list_post = Post::quickSelect();
|
||||
|
||||
if (empty($post_id)) {
|
||||
$model_post = $list_post->first();
|
||||
|
||||
5
app/index/route/app.php
Normal file
5
app/index/route/app.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Route;
|
||||
|
||||
Route::rule('doc/[:post_id]','Index/index');
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\App;
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
@@ -153,4 +154,19 @@ class Post extends Model
|
||||
|
||||
return file_get_contents($file_path);
|
||||
}
|
||||
|
||||
public static function quickSelect($clear = false)
|
||||
{
|
||||
$cacke_key = 'post_list';
|
||||
|
||||
$list_post = Cache::get($cacke_key);
|
||||
|
||||
if (empty($list_post) || $clear) {
|
||||
$list_post = Post::where('status', 1)->order('sort desc')->select();
|
||||
Cache::set($cacke_key, $list_post,600);
|
||||
}
|
||||
|
||||
return $list_post;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user