test_service d3170b4d1c 1
2023-12-01 15:43:29 +08:00

62 lines
1.5 KiB
PHP
Executable File

<?php
namespace app\admin\controller\setting;
use app\admin\controller\Controller;
use think\facade\Cache as Driver;
use think\facade\View;
/**
* 清理缓存
*/
class Cache extends Controller
{
/**
* 清理缓存
*/
public function clear($isForce = false)
{
if ($this->request->isAjax()) {
$data = $this->postData('cache');
$this->rmCache($data['keys'], isset($data['isForce']) ? !!$data['isForce'] : false);
return $this->renderSuccess('操作成功');
}
return View::fetch('clear', [
'cacheList' => $this->getCacheKeys(),
'isForce' => !!$isForce ?: config('app_debug'),
]);
}
/**
* 删除缓存
*/
private function rmCache($keys, $isForce = false)
{
if ($isForce === true) {
Driver::clear();
} else {
$cacheList = $this->getCacheKeys();
foreach (array_intersect(array_keys($cacheList), $keys) as $key) {
Driver::has($cacheList[$key]['key']) && Driver::delete($cacheList[$key]['key']);
}
}
}
/**
* 获取缓存索引数据
*/
private function getCacheKeys()
{
return [
'setting' => [
'key' => 'setting_0',
'name' => '站点设置'
],
'link' => [
'key' => 'hema_link',
'name' => '友情链接'
],
];
}
}