完善缓存读取;

This commit is contained in:
2022-03-28 10:36:14 +08:00
parent 807ea5f4f9
commit 96b870caca
3 changed files with 22 additions and 23 deletions

View File

@@ -80,6 +80,6 @@ class System extends Common
{ {
Cache::clear(); Cache::clear();
return $this->success('清成功'); return $this->success('清成功');
} }
} }

View File

@@ -155,7 +155,6 @@ class Post extends Model
$base_dir = App::getRootPath() . '/demo/' . $this->getAttr('category')->getData('tpl_name') . '/'; $base_dir = App::getRootPath() . '/demo/' . $this->getAttr('category')->getData('tpl_name') . '/';
$file_path = $base_dir . $this->getData('tpl_name') . '.html'; $file_path = $base_dir . $this->getData('tpl_name') . '.html';
if (!file_exists($file_path)) { if (!file_exists($file_path)) {
return ''; return '';
} }
@@ -191,7 +190,7 @@ class Post extends Model
$model_post = Cache::get($cache_key); $model_post = Cache::get($cache_key);
if (empty($model_post) || $clear) { if (empty($model_post) || $clear) {
$model_post = Post::find($id); $model_post = Post::with(['category'], 'left')->find($id);
Cache::set($cache_key, $model_post, get_system_config('cache_expire_time')); Cache::set($cache_key, $model_post, get_system_config('cache_expire_time'));
} }
@@ -204,7 +203,7 @@ class Post extends Model
$model_post = Cache::get($cache_key); $model_post = Cache::get($cache_key);
if (empty($model_post) || $clear) { if (empty($model_post) || $clear) {
$model_post = Post::where('tpl_name', $tpl_name)->find(); $model_post = Post::with(['category'], 'left')->where('tpl_name', $tpl_name)->find();
Cache::set($cache_key, $model_post, get_system_config('cache_expire_time')); Cache::set($cache_key, $model_post, get_system_config('cache_expire_time'));
} }

View File

@@ -9,25 +9,25 @@ use think\facade\Env;
return [ return [
// 默认缓存驱动 // 默认缓存驱动
'default' => Env::get('cache.driver', 'file'), 'default' => Env::get('cache.driver', 'file'),
// 缓存连接方式配置 // 缓存连接方式配置
'stores' => [ 'stores' => [
'file' => [ 'file' => [
// 驱动方式 // 驱动方式
'type' => 'File', 'type' => 'File',
// 缓存保存目录 // 缓存保存目录
'path' => App::getRootPath() . 'runtime/cache', 'path' => App::getRootPath() . 'runtime/cache',
// 缓存前缀 // 缓存前缀
'prefix' => '', 'prefix' => '',
// 缓存有效期 0表示永久缓存 // 缓存有效期 0表示永久缓存
'expire' => 0, 'expire' => 0,
// 缓存标签前缀 // 缓存标签前缀
'tag_prefix' => 'tag:', 'tag_prefix' => 'tag:',
// 序列化机制 例如 ['serialize', 'unserialize'] // 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [], 'serialize' => [],
],
// 更多的缓存连接
], ],
// 更多的缓存连接
],
]; ];