perf: 对查询参数信息接口增加缓存处理

This commit is contained in:
Charles7c 2023-09-24 10:58:24 +08:00
parent b7c504ab8f
commit 243ac0104a
3 changed files with 12 additions and 0 deletions

View File

@ -58,6 +58,11 @@ public class CacheConsts {
*/
public static final String DICT_KEY_PREFIX = "DICT";
/**
* 参数缓存键前缀
*/
public static final String OPTION_KEY_PREFIX = "OPTION";
/**
* 仪表盘缓存键前缀
*/

View File

@ -20,10 +20,13 @@ import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import top.charles7c.cnadmin.common.constant.CacheConsts;
import top.charles7c.cnadmin.common.util.helper.QueryHelper;
import top.charles7c.cnadmin.system.mapper.OptionMapper;
import top.charles7c.cnadmin.system.model.entity.OptionDO;
@ -41,6 +44,7 @@ import top.charles7c.cnadmin.system.service.OptionService;
*/
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = CacheConsts.OPTION_KEY_PREFIX)
public class OptionServiceImpl implements OptionService {
private final OptionMapper baseMapper;
@ -51,11 +55,13 @@ public class OptionServiceImpl implements OptionService {
}
@Override
@CacheEvict(allEntries = true)
public void update(List<OptionRequest> request) {
baseMapper.updateBatchById(BeanUtil.copyToList(request, OptionDO.class));
}
@Override
@CacheEvict(allEntries = true)
public void resetValue(ResetOptionValueRequest request) {
baseMapper.lambdaUpdate().set(OptionDO::getValue, null).in(OptionDO::getCode, request.getCode()).update();
}

View File

@ -129,6 +129,7 @@ public class CommonController {
@SaIgnore
@Operation(summary = "查询参数", description = "查询参数")
@GetMapping("/option")
@Cacheable(cacheNames = CacheConsts.OPTION_KEY_PREFIX)
public R<List<LabelValueVO>> listOption(@Validated OptionQuery query) {
return R.ok(optionService.list(query).stream().map(option -> new LabelValueVO(option.getCode(),
StrUtil.nullToDefault(option.getValue(), option.getDefaultValue()))).collect(Collectors.toList()));