diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index 11ec3a9..d406c8a 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -40,6 +40,21 @@ Class FrontApiController extends SiteController { return $this->renderJson(compact('code', 'msg', 'err', 'data')); } + //删除当前用户的缓存数据 + protected function cleanAllFilesCache() { + if (empty(FSC::$app['user_id'])) {return false;} + + $prefix = FSC::$app['user_id']; + + $cacheKey = "{$prefix}_allFilesTree"; + Common::cleanFileCache($cacheKey); + + $cacheKey = "{$prefix}_allFilesData"; + Common::cleanFileCache($cacheKey); + + return true; + } + /* * 参数: * content: 从抖音或其它平台复制出来的视频分享内容,或者视频网址 @@ -149,6 +164,9 @@ Class FrontApiController extends SiteController { $stats = TajianStats::init(); TajianStats::increase('video'); $saved = TajianStats::save(); + + //清空缓存 + $this->cleanAllFilesCache(); } } @@ -897,6 +915,9 @@ eof; //保存 $saved = $this->saveTags($tags, $allTags); if (!empty($saved)) { + //清空缓存 + $this->cleanAllFilesCache(); + $msg = "分类已保存"; $code = 1; }else { @@ -958,6 +979,9 @@ eof; TajianStats::decrease('tag'); $saved = TajianStats::save(); + //清空缓存 + $this->cleanAllFilesCache(); + $msg = "分类已删除"; $code = 1; }else { @@ -1038,6 +1062,9 @@ eof; TajianStats::increase('tag'); $saved = TajianStats::save(); + //清空缓存 + $this->cleanAllFilesCache(); + $msg = "分类已添加"; $code = 1; }else { @@ -1116,6 +1143,8 @@ eof; TajianStats::decrease('video'); $saved = TajianStats::save(); + //清空缓存 + $this->cleanAllFilesCache(); $msg = "视频已删除"; $code = 1; @@ -1183,6 +1212,9 @@ eof; } if ($saved !== false) { + //清空缓存 + $this->cleanAllFilesCache(); + $msg = "操作完成"; $code = 1; }else { @@ -1255,6 +1287,9 @@ eof; $saved = Common::createNewFavDir($loginedUser['cellphone'], $loginedUser['username'], $new_dir, $new_nickname); if ($saved !== false) { + //清空缓存 + $this->cleanAllFilesCache(); + $msg = "新账号创建完成"; $code = 1; }else { diff --git a/themes/tajian/controller/ListController.php b/themes/tajian/controller/ListController.php index 544b0fb..ef5dc2e 100644 --- a/themes/tajian/controller/ListController.php +++ b/themes/tajian/controller/ListController.php @@ -4,6 +4,7 @@ */ require_once __DIR__ . '/../../../lib/DirScanner.php'; require_once __DIR__ . '/../../../plugins/Parsedown.php'; +require_once __DIR__ . '/../../../plugins/Common.php'; require_once __DIR__ . '/SiteController.php'; Class ListController extends SiteController { @@ -16,8 +17,30 @@ Class ListController extends SiteController { $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); - $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); - $scanResults = $scanner->getScanResults(); + + //优先从缓存读取数据 + $prefix = FSC::$app['user_id']; + $cacheKey = "{$prefix}_allFilesTree"; + $cachedData = Common::getCacheFromFile($cacheKey); + if (!empty($cachedData)) { + $dirTree = $cachedData; + $scanner->setTreeData($cachedData); + }else { + $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); + Common::saveCacheToFile($cacheKey, $dirTree); + } + + //优先从缓存读取数据 + $cacheKey = "{$prefix}_allFilesData"; + $cachedData = Common::getCacheFromFile($cacheKey); + if (!empty($cachedData)) { + $scanResults = $cachedData; + $scanner->setScanResults($cachedData); + }else { + $scanResults = $scanner->getScanResults(); + Common::saveCacheToFile($cacheKey, $scanResults); + } + $titles = array(); $readmeFile = $scanner->getDefaultReadme(); diff --git a/themes/tajian/controller/SiteController.php b/themes/tajian/controller/SiteController.php index a9d877b..670fa33 100644 --- a/themes/tajian/controller/SiteController.php +++ b/themes/tajian/controller/SiteController.php @@ -38,8 +38,30 @@ Class SiteController extends Controller { $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); - $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); - $scanResults = $scanner->getScanResults(); + + //优先从缓存读取数据 + $prefix = FSC::$app['user_id']; + $cacheKey = "{$prefix}_allFilesTree"; + $cachedData = Common::getCacheFromFile($cacheKey); + if (!empty($cachedData)) { + $dirTree = $cachedData; + $scanner->setTreeData($cachedData); + }else { + $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); + Common::saveCacheToFile($cacheKey, $dirTree); + } + + //优先从缓存读取数据 + $cacheKey = "{$prefix}_allFilesData"; + $cachedData = Common::getCacheFromFile($cacheKey); + if (!empty($cachedData)) { + $scanResults = $cachedData; + $scanner->setScanResults($cachedData); + }else { + $scanResults = $scanner->getScanResults(); + Common::saveCacheToFile($cacheKey, $scanResults); + } + //获取目录 $menus = $scanner->getMenus(); @@ -346,8 +368,30 @@ Class SiteController extends Controller { $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); - $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); - $scanResults = $scanner->getScanResults(); + + //优先从缓存读取数据 + $prefix = FSC::$app['user_id']; + $cacheKey = "{$prefix}_allFilesTree"; + $cachedData = Common::getCacheFromFile($cacheKey); + if (!empty($cachedData)) { + $dirTree = $cachedData; + $scanner->setTreeData($cachedData); + }else { + $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); + Common::saveCacheToFile($cacheKey, $dirTree); + } + + //优先从缓存读取数据 + $cacheKey = "{$prefix}_allFilesData"; + $cachedData = Common::getCacheFromFile($cacheKey); + if (!empty($cachedData)) { + $scanResults = $cachedData; + $scanner->setScanResults($cachedData); + }else { + $scanResults = $scanner->getScanResults(); + Common::saveCacheToFile($cacheKey, $scanResults); + } + $titles = array(); $htmlReadme = '';