refactor: 优化部分缓存使用

This commit is contained in:
2024-06-15 19:00:35 +08:00
parent d5f3c7417a
commit 624f5e0114
3 changed files with 4 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ package top.continew.admin.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alicp.jetcache.anno.CacheInvalidate;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -79,7 +80,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuRes
}
@Override
@Cached(key = "'ALL'", name = CacheConstants.MENU_KEY_PREFIX)
@Cached(key = "'ALL'", name = CacheConstants.MENU_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public List<MenuResp> listAll() {
return super.list(new MenuQuery(DisEnableStatusEnum.ENABLE.getValue()), null);
}

View File

@@ -267,7 +267,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
}
@Override
@Cached(key = "#id", cacheType = CacheType.BOTH, name = CacheConstants.USER_KEY_PREFIX, syncLocal = true)
@Cached(key = "#id", name = CacheConstants.USER_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public String getNicknameById(Long id) {
return baseMapper.selectNicknameById(id);
}

View File

@@ -70,7 +70,7 @@ public class DashboardController {
@GetMapping("/access/trend/{days}")
@CachePenetrationProtect
@CacheRefresh(refresh = 7200)
@Cached(key = "#days", cacheType = CacheType.BOTH, name = CacheConstants.DASHBOARD_KEY_PREFIX, syncLocal = true)
@Cached(key = "#days", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public R<List<DashboardAccessTrendResp>> listAccessTrend(@PathVariable Integer days) {
ValidationUtils.throwIf(7 != days && 30 != days, "仅支持查询近 7/30 天访问趋势信息");
return R.ok(dashboardService.listAccessTrend(days));