Browse Source

add file cache support

master
filesite 5 months ago
parent
commit
47838693d5
  1. 22
      themes/beauty/controller/ListController.php

22
themes/beauty/controller/ListController.php

@ -4,6 +4,7 @@
*/ */
require_once __DIR__ . '/../../../lib/DirScanner.php'; require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php'; require_once __DIR__ . '/../../../plugins/Parsedown.php';
require_once __DIR__ . '/../../../plugins/Common.php';
Class ListController extends Controller { Class ListController extends Controller {
@ -16,8 +17,29 @@ Class ListController extends Controller {
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $scanner->setWebRoot(FSC::$app['config']['content_directory']);
//优先从缓存读取数据
$cacheKey = 'allFilesTree';
$cachedData = Common::getCacheFromFile($cacheKey);
if (!empty($cachedData)) {
$dirTree = $cachedData;
$scanner->setTreeData($cachedData);
}else {
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
Common::saveCacheToFile($cacheKey, $dirTree);
}
//优先从缓存读取数据
$cacheKey = 'allFilesData';
$cachedData = Common::getCacheFromFile($cacheKey);
if (!empty($cachedData)) {
$scanResults = $cachedData;
$scanner->setScanResults($cachedData);
}else {
$scanResults = $scanner->getScanResults(); $scanResults = $scanner->getScanResults();
Common::saveCacheToFile($cacheKey, $scanResults);
}
//获取目录 //获取目录
$menus = $scanner->getMenus(); $menus = $scanner->getMenus();

Loading…
Cancel
Save