From 22a87069754be43b6438930064d4189914d3092f Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 10 Jul 2024 11:34:58 +0800 Subject: [PATCH] readme in root dir save into cache --- themes/beauty/controller/ListController.php | 9 +++++++- themes/beauty/controller/SiteController.php | 25 ++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/themes/beauty/controller/ListController.php b/themes/beauty/controller/ListController.php index 7fc6474..96c0243 100644 --- a/themes/beauty/controller/ListController.php +++ b/themes/beauty/controller/ListController.php @@ -89,7 +89,14 @@ Class ListController extends Controller { //非首页统一从缓存获取目录数据,有效期 1 小时 $cacheKey = $this->getCacheKey('all', 'menu', $maxScanDeep); $menus = Common::getCacheFromFile($cacheKey, 3600); - + + //获取根目录下的readme + $cacheKey = $this->getCacheKey('root', 'readme', $maxScanDeep); + $cachedData = Common::getCacheFromFile($cacheKey); + if (!empty($cachedData)) { + $htmlReadme = $cachedData['htmlReadme']; + } + //获取目录面包屑 $subcate = $scanResults[$cateId]; diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index ad73468..30f432e 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -81,14 +81,23 @@ Class SiteController extends Controller { //获取联系方式 $titles = array(); - $readmeFile = $scanner->getDefaultReadme(); - if (!empty($readmeFile)) { - $titles = $scanner->getMDTitles($readmeFile['id']); - - $Parsedown = new Parsedown(); - $content = file_get_contents($readmeFile['realpath']); - $htmlReadme = $Parsedown->text($content); - $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); + $cacheKey = $this->getCacheKey('root', 'readme', $maxScanDeep); + $cachedData = Common::getCacheFromFile($cacheKey); + if (empty($cachedData)) { + $readmeFile = $scanner->getDefaultReadme(); + if (!empty($readmeFile)) { + $titles = $scanner->getMDTitles($readmeFile['id']); + + $Parsedown = new Parsedown(); + $content = file_get_contents($readmeFile['realpath']); + $htmlReadme = $Parsedown->text($content); + $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); + + Common::saveCacheToFile($cacheKey, array('htmlReadme' => $htmlReadme, 'titles' => $titles)); + } + }else { + $htmlReadme = $cachedData['htmlReadme']; + $titles = $cachedData['titles']; }