Browse Source

readme in root dir save into cache

master
filesite 5 months ago
parent
commit
22a8706975
  1. 9
      themes/beauty/controller/ListController.php
  2. 25
      themes/beauty/controller/SiteController.php

9
themes/beauty/controller/ListController.php

@ -89,7 +89,14 @@ Class ListController extends Controller {
//非首页统一从缓存获取目录数据,有效期 1 小时 //非首页统一从缓存获取目录数据,有效期 1 小时
$cacheKey = $this->getCacheKey('all', 'menu', $maxScanDeep); $cacheKey = $this->getCacheKey('all', 'menu', $maxScanDeep);
$menus = Common::getCacheFromFile($cacheKey, 3600); $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]; $subcate = $scanResults[$cateId];

25
themes/beauty/controller/SiteController.php

@ -81,14 +81,23 @@ Class SiteController extends Controller {
//获取联系方式 //获取联系方式
$titles = array(); $titles = array();
$readmeFile = $scanner->getDefaultReadme(); $cacheKey = $this->getCacheKey('root', 'readme', $maxScanDeep);
if (!empty($readmeFile)) { $cachedData = Common::getCacheFromFile($cacheKey);
$titles = $scanner->getMDTitles($readmeFile['id']); if (empty($cachedData)) {
$readmeFile = $scanner->getDefaultReadme();
$Parsedown = new Parsedown(); if (!empty($readmeFile)) {
$content = file_get_contents($readmeFile['realpath']); $titles = $scanner->getMDTitles($readmeFile['id']);
$htmlReadme = $Parsedown->text($content);
$htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); $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'];
} }

Loading…
Cancel
Save