【fastadmin】利用后台清除缓存按钮,来清除自定义的缓存
业务处
if (!function_exists('get_shopro_config')) {
function get_shopro_config($name, $field)
{
$cache_key = 'shopro_config_' . $name . '_' . $field;
$cache_data = cache($cache_key);
if (!empty($cache_data)) return $cache_data;
$value = \think\Db::name('shopro_config')->where(['name' => $name])->value('value');
if (empty($value)) {
$config_value = '';
} else {
$value_arr = json_decode($value, true);
if (!empty($value_arr[$field])) {
$config_value = $value_arr[$field];
} else {
$config_value = '';
}
}
\think\Cache::tag('shopro_config')->set($cache_key, $config_value, 3600);
return $config_value;
}
}
代码 \think\Cache::tag('shopro_config')->set($cache_key, $config_value, 3600);
对缓存进行设置标签,然后利用tp框架清除指定的标签缓存。
后台
在application/admin/controller/Ajax.php
文件修改
/**
* 清空系统缓存
*/
public function wipecache()
{
try {
$type = $this->request->request("type");
switch ($type) {
case 'all':
// no break
\think\Cache::clear('shopro_config');
代码 \think\Cache::clear('shopro_config');