Browse Source

add cache for tajian

master
filesite 5 months ago
parent
commit
89aa75e6be
  1. 35
      themes/tajian/controller/FrontapiController.php
  2. 27
      themes/tajian/controller/ListController.php
  3. 52
      themes/tajian/controller/SiteController.php

35
themes/tajian/controller/FrontapiController.php

@ -40,6 +40,21 @@ Class FrontApiController extends SiteController {
return $this->renderJson(compact('code', 'msg', 'err', 'data')); 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: 从抖音或其它平台复制出来的视频分享内容,或者视频网址 * content: 从抖音或其它平台复制出来的视频分享内容,或者视频网址
@ -149,6 +164,9 @@ Class FrontApiController extends SiteController {
$stats = TajianStats::init(); $stats = TajianStats::init();
TajianStats::increase('video'); TajianStats::increase('video');
$saved = TajianStats::save(); $saved = TajianStats::save();
//清空缓存
$this->cleanAllFilesCache();
} }
} }
@ -897,6 +915,9 @@ eof;
//保存 //保存
$saved = $this->saveTags($tags, $allTags); $saved = $this->saveTags($tags, $allTags);
if (!empty($saved)) { if (!empty($saved)) {
//清空缓存
$this->cleanAllFilesCache();
$msg = "分类已保存"; $msg = "分类已保存";
$code = 1; $code = 1;
}else { }else {
@ -958,6 +979,9 @@ eof;
TajianStats::decrease('tag'); TajianStats::decrease('tag');
$saved = TajianStats::save(); $saved = TajianStats::save();
//清空缓存
$this->cleanAllFilesCache();
$msg = "分类已删除"; $msg = "分类已删除";
$code = 1; $code = 1;
}else { }else {
@ -1038,6 +1062,9 @@ eof;
TajianStats::increase('tag'); TajianStats::increase('tag');
$saved = TajianStats::save(); $saved = TajianStats::save();
//清空缓存
$this->cleanAllFilesCache();
$msg = "分类已添加"; $msg = "分类已添加";
$code = 1; $code = 1;
}else { }else {
@ -1116,6 +1143,8 @@ eof;
TajianStats::decrease('video'); TajianStats::decrease('video');
$saved = TajianStats::save(); $saved = TajianStats::save();
//清空缓存
$this->cleanAllFilesCache();
$msg = "视频已删除"; $msg = "视频已删除";
$code = 1; $code = 1;
@ -1183,6 +1212,9 @@ eof;
} }
if ($saved !== false) { if ($saved !== false) {
//清空缓存
$this->cleanAllFilesCache();
$msg = "操作完成"; $msg = "操作完成";
$code = 1; $code = 1;
}else { }else {
@ -1255,6 +1287,9 @@ eof;
$saved = Common::createNewFavDir($loginedUser['cellphone'], $loginedUser['username'], $new_dir, $new_nickname); $saved = Common::createNewFavDir($loginedUser['cellphone'], $loginedUser['username'], $new_dir, $new_nickname);
if ($saved !== false) { if ($saved !== false) {
//清空缓存
$this->cleanAllFilesCache();
$msg = "新账号创建完成"; $msg = "新账号创建完成";
$code = 1; $code = 1;
}else { }else {

27
themes/tajian/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';
require_once __DIR__ . '/SiteController.php'; require_once __DIR__ . '/SiteController.php';
Class ListController extends SiteController { Class ListController extends SiteController {
@ -16,8 +17,30 @@ Class ListController extends SiteController {
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $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(); $titles = array();
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();

52
themes/tajian/controller/SiteController.php

@ -38,8 +38,30 @@ Class SiteController extends Controller {
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $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(); $menus = $scanner->getMenus();
@ -346,8 +368,30 @@ Class SiteController extends Controller {
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $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(); $titles = array();
$htmlReadme = ''; $htmlReadme = '';

Loading…
Cancel
Save