From e5adb55ce698f508c7954f7ecaa48aaef60978d7 Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 8 Jul 2024 08:51:31 +0800 Subject: [PATCH] add cache clean function --- themes/beauty/controller/SiteController.php | 14 ++++++++++++++ www/js/beauty.js | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index 05d9e25..db693c4 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -107,4 +107,18 @@ Class SiteController extends Controller { return $this->render($viewName, $params, $pageTitle); } + //清空缓存 + public function actionCleancache() { + $prefix = FSC::$app['config']['theme']; + $cacheKey = "{$prefix}_allFilesTree"; + Common::cleanFileCache($cacheKey); + + $cacheKey = "{$prefix}_allFilesData"; + Common::cleanFileCache($cacheKey); + + $code = 1; + $msg = 'OK'; + return $this->renderJson(compact('code', 'msg')); + } + } diff --git a/www/js/beauty.js b/www/js/beauty.js index cafc968..e3926fb 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -109,6 +109,21 @@ if ($('#image_site').get(0)) { saveLanpnumToLocalstorage(lanpnum); }); + //刷新缓存 + $('.cleanCacheJS').click(function () { + $.ajax({ + url: '/site/cleancache', + dataType: 'json', + method: 'POST' + }).done(function(data) { + if (data.code == 1) { + location.reload(); + } + }).fail(function(jqXHR, textStatus, errorThrown) { + alert('请求失败,请稍后重试,错误信息:' + errorThrown); + }); + }); + // 音乐播放 if ($('#music_main').length > 0) { var musicState = 0;