refactor: 移除 Spring Cache,初步适配 JetCache

1.移除 ContiNew Starter Spring Cache
2.初步适配 ContiNew Starter JetCache
3.优化缓存键前缀常量的使用
This commit is contained in:
Charles7c 2024-01-14 14:39:41 +08:00
parent 754de79200
commit d4bb39d9b4
15 changed files with 187 additions and 154 deletions

View File

@ -81,10 +81,10 @@
<artifactId>continew-starter-data-mybatis-plus</artifactId> <artifactId>continew-starter-data-mybatis-plus</artifactId>
</dependency> </dependency>
<!-- ContiNew Starter 缓存模块 - Spring Cache --> <!-- ContiNew Starter 缓存模块 - JetCache -->
<dependency> <dependency>
<groupId>top.charles7c.continew</groupId> <groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-cache-springcache</artifactId> <artifactId>continew-starter-cache-jetcache</artifactId>
</dependency> </dependency>
<!-- ContiNew Starter 消息模块 - 邮件 --> <!-- ContiNew Starter 消息模块 - 邮件 -->

View File

@ -18,6 +18,7 @@ package top.charles7c.continew.admin.common.constant;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import top.charles7c.continew.starter.core.constant.StringConstants;
/** /**
* 缓存相关常量 * 缓存相关常量
@ -28,6 +29,11 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CacheConstants { public class CacheConstants {
/**
* 分隔符
*/
public static final String DELIMITER = StringConstants.COLON;
/** /**
* 登录用户键 * 登录用户键
*/ */
@ -36,35 +42,35 @@ public class CacheConstants {
/** /**
* 验证码键前缀 * 验证码键前缀
*/ */
public static final String CAPTCHA_KEY_PREFIX = "CAPTCHA"; public static final String CAPTCHA_KEY_PREFIX = "CAPTCHA" + DELIMITER;
/** /**
* 限流键前缀 * 限流键前缀
*/ */
public static final String LIMIT_KEY_PREFIX = "LIMIT"; public static final String LIMIT_KEY_PREFIX = "LIMIT" + DELIMITER;
/** /**
* 用户缓存键前缀 * 用户缓存键前缀
*/ */
public static final String USER_KEY_PREFIX = "USER"; public static final String USER_KEY_PREFIX = "USER" + DELIMITER;
/** /**
* 菜单缓存键前缀 * 菜单缓存键前缀
*/ */
public static final String MENU_KEY_PREFIX = "MENU"; public static final String MENU_KEY_PREFIX = "MENU" + DELIMITER;
/** /**
* 字典缓存键前缀 * 字典缓存键前缀
*/ */
public static final String DICT_KEY_PREFIX = "DICT"; public static final String DICT_KEY_PREFIX = "DICT" + DELIMITER;
/** /**
* 参数缓存键前缀 * 参数缓存键前缀
*/ */
public static final String OPTION_KEY_PREFIX = "OPTION"; public static final String OPTION_KEY_PREFIX = "OPTION" + DELIMITER;
/** /**
* 仪表盘缓存键前缀 * 仪表盘缓存键前缀
*/ */
public static final String DASHBOARD_KEY_PREFIX = "DASHBOARD"; public static final String DASHBOARD_KEY_PREFIX = "DASHBOARD" + DELIMITER;
} }

View File

@ -16,19 +16,14 @@
package top.charles7c.continew.admin.monitor.service.impl; package top.charles7c.continew.admin.monitor.service.impl;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import com.alicp.jetcache.anno.CachePenetrationProtect;
import com.alicp.jetcache.anno.CacheRefresh;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.charles7c.continew.admin.common.constant.CacheConstants; import top.charles7c.continew.admin.common.constant.CacheConstants;
import top.charles7c.continew.admin.monitor.model.resp.DashboardAccessTrendResp; import top.charles7c.continew.admin.monitor.model.resp.DashboardAccessTrendResp;
import top.charles7c.continew.admin.monitor.model.resp.DashboardGeoDistributionResp; import top.charles7c.continew.admin.monitor.model.resp.DashboardGeoDistributionResp;
@ -39,6 +34,10 @@ import top.charles7c.continew.admin.monitor.service.LogService;
import top.charles7c.continew.admin.system.model.resp.DashboardAnnouncementResp; import top.charles7c.continew.admin.system.model.resp.DashboardAnnouncementResp;
import top.charles7c.continew.admin.system.service.AnnouncementService; import top.charles7c.continew.admin.system.service.AnnouncementService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/** /**
* 仪表盘业务实现 * 仪表盘业务实现
* *
@ -47,7 +46,6 @@ import top.charles7c.continew.admin.system.service.AnnouncementService;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@CacheConfig(cacheNames = CacheConstants.DASHBOARD_KEY_PREFIX)
public class DashboardServiceImpl implements DashboardService { public class DashboardServiceImpl implements DashboardService {
private final LogService logService; private final LogService logService;
@ -67,7 +65,9 @@ public class DashboardServiceImpl implements DashboardService {
} }
@Override @Override
@Cacheable(key = "#days") @CachePenetrationProtect
@CacheRefresh(refresh = 7200)
@Cached(key = "#days", cacheType = CacheType.BOTH, name = CacheConstants.DASHBOARD_KEY_PREFIX)
public List<DashboardAccessTrendResp> listAccessTrend(Integer days) { public List<DashboardAccessTrendResp> listAccessTrend(Integer days) {
return logService.listDashboardAccessTrend(days); return logService.listDashboardAccessTrend(days);
} }

View File

@ -17,10 +17,7 @@
package top.charles7c.continew.admin.system.service.impl; package top.charles7c.continew.admin.system.service.impl;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import top.charles7c.continew.admin.common.constant.CacheConstants;
import top.charles7c.continew.admin.common.model.resp.LabelValueResp; import top.charles7c.continew.admin.common.model.resp.LabelValueResp;
import top.charles7c.continew.admin.system.mapper.DictItemMapper; import top.charles7c.continew.admin.system.mapper.DictItemMapper;
import top.charles7c.continew.admin.system.model.entity.DictItemDO; import top.charles7c.continew.admin.system.model.entity.DictItemDO;
@ -43,11 +40,9 @@ import java.util.List;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@CacheConfig(cacheNames = CacheConstants.DICT_KEY_PREFIX)
public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictItemDO, DictItemResp, DictItemDetailResp, DictItemQuery, DictItemReq> implements DictItemService { public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictItemDO, DictItemResp, DictItemDetailResp, DictItemQuery, DictItemReq> implements DictItemService {
@Override @Override
@CacheEvict(allEntries = true)
public Long add(DictItemReq req) { public Long add(DictItemReq req) {
String value = req.getValue(); String value = req.getValue();
CheckUtils.throwIf(this.isValueExists(value, null, req.getDictId()), "新增失败,字典值 [{}] 已存在", value); CheckUtils.throwIf(this.isValueExists(value, null, req.getDictId()), "新增失败,字典值 [{}] 已存在", value);
@ -55,7 +50,7 @@ public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictIte
} }
@Override @Override
@CacheEvict(allEntries = true) // @CacheInvalidate(key = "#id", name = CacheConstants.DICT_KEY_PREFIX)
public void update(DictItemReq req, Long id) { public void update(DictItemReq req, Long id) {
String value = req.getValue(); String value = req.getValue();
CheckUtils.throwIf(this.isValueExists(value, id, req.getDictId()), "修改失败,字典值 [{}] 已存在", value); CheckUtils.throwIf(this.isValueExists(value, id, req.getDictId()), "修改失败,字典值 [{}] 已存在", value);
@ -79,7 +74,7 @@ public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictIte
} }
@Override @Override
@CacheEvict(allEntries = true) // @CacheInvalidate(key = "#dictIds", name = CacheConstants.DICT_KEY_PREFIX, multi = true)
public void deleteByDictIds(List<Long> dictIds) { public void deleteByDictIds(List<Long> dictIds) {
baseMapper.lambdaUpdate().in(DictItemDO::getDictId, dictIds).remove(); baseMapper.lambdaUpdate().in(DictItemDO::getDictId, dictIds).remove();
} }

View File

@ -16,18 +16,12 @@
package top.charles7c.continew.admin.system.service.impl; package top.charles7c.continew.admin.system.service.impl;
import java.util.*; import cn.hutool.core.bean.BeanUtil;
import com.alicp.jetcache.anno.CacheInvalidate;
import com.alicp.jetcache.anno.Cached;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.bean.BeanUtil;
import top.charles7c.continew.admin.common.constant.CacheConstants; import top.charles7c.continew.admin.common.constant.CacheConstants;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum; import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.admin.system.mapper.MenuMapper; import top.charles7c.continew.admin.system.mapper.MenuMapper;
@ -39,6 +33,9 @@ import top.charles7c.continew.admin.system.service.MenuService;
import top.charles7c.continew.starter.core.util.validate.CheckUtils; import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.extension.crud.base.BaseServiceImpl; import top.charles7c.continew.starter.extension.crud.base.BaseServiceImpl;
import java.util.List;
import java.util.Set;
/** /**
* 菜单业务实现 * 菜单业务实现
* *
@ -47,11 +44,10 @@ import top.charles7c.continew.starter.extension.crud.base.BaseServiceImpl;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@CacheConfig(cacheNames = CacheConstants.MENU_KEY_PREFIX)
public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuResp, MenuResp, MenuQuery, MenuReq> implements MenuService { public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuResp, MenuResp, MenuQuery, MenuReq> implements MenuService {
@Override @Override
@CacheEvict(allEntries = true) @CacheInvalidate(key = "'ALL'", name = CacheConstants.MENU_KEY_PREFIX)
public Long add(MenuReq req) { public Long add(MenuReq req) {
String title = req.getTitle(); String title = req.getTitle();
CheckUtils.throwIf(this.isNameExists(title, req.getParentId(), null), "新增失败,[{}] 已存在", title); CheckUtils.throwIf(this.isNameExists(title, req.getParentId(), null), "新增失败,[{}] 已存在", title);
@ -60,7 +56,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuRes
} }
@Override @Override
@CacheEvict(allEntries = true) @CacheInvalidate(key = "#id", name = CacheConstants.MENU_KEY_PREFIX)
public void update(MenuReq req, Long id) { public void update(MenuReq req, Long id) {
String title = req.getTitle(); String title = req.getTitle();
CheckUtils.throwIf(this.isNameExists(title, req.getParentId(), id), "修改失败,[{}] 已存在", title); CheckUtils.throwIf(this.isNameExists(title, req.getParentId(), id), "修改失败,[{}] 已存在", title);
@ -68,7 +64,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuRes
} }
@Override @Override
@CacheEvict(allEntries = true) @CacheInvalidate(key = "#ids", name = CacheConstants.MENU_KEY_PREFIX, multi = true)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(List<Long> ids) { public void delete(List<Long> ids) {
baseMapper.lambdaUpdate().in(MenuDO::getParentId, ids).remove(); baseMapper.lambdaUpdate().in(MenuDO::getParentId, ids).remove();
@ -81,7 +77,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuRes
} }
@Override @Override
@Cacheable(key = "#roleCode") @Cached(key = "#roleCode", name = CacheConstants.MENU_KEY_PREFIX)
public List<MenuResp> listByRoleCode(String roleCode) { public List<MenuResp> listByRoleCode(String roleCode) {
List<MenuDO> menuList = baseMapper.selectListByRoleCode(roleCode); List<MenuDO> menuList = baseMapper.selectListByRoleCode(roleCode);
List<MenuResp> list = BeanUtil.copyToList(menuList, MenuResp.class); List<MenuResp> list = BeanUtil.copyToList(menuList, MenuResp.class);
@ -90,7 +86,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuRes
} }
@Override @Override
@Cacheable(key = "'ALL'") @Cached(key = "'ALL'", name = CacheConstants.MENU_KEY_PREFIX)
public List<MenuResp> list() { public List<MenuResp> list() {
MenuQuery menuQuery = new MenuQuery(); MenuQuery menuQuery = new MenuQuery();
menuQuery.setStatus(DisEnableStatusEnum.ENABLE.getValue()); menuQuery.setStatus(DisEnableStatusEnum.ENABLE.getValue());

View File

@ -16,16 +16,10 @@
package top.charles7c.continew.admin.system.service.impl; package top.charles7c.continew.admin.system.service.impl;
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 cn.hutool.core.bean.BeanUtil;
import com.alicp.jetcache.anno.CacheInvalidate;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.charles7c.continew.admin.common.constant.CacheConstants; import top.charles7c.continew.admin.common.constant.CacheConstants;
import top.charles7c.continew.admin.system.mapper.OptionMapper; import top.charles7c.continew.admin.system.mapper.OptionMapper;
import top.charles7c.continew.admin.system.model.entity.OptionDO; import top.charles7c.continew.admin.system.model.entity.OptionDO;
@ -36,6 +30,8 @@ import top.charles7c.continew.admin.system.model.resp.OptionResp;
import top.charles7c.continew.admin.system.service.OptionService; import top.charles7c.continew.admin.system.service.OptionService;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryHelper; import top.charles7c.continew.starter.data.mybatis.plus.query.QueryHelper;
import java.util.List;
/** /**
* 参数业务实现 * 参数业务实现
* *
@ -44,7 +40,6 @@ import top.charles7c.continew.starter.data.mybatis.plus.query.QueryHelper;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@CacheConfig(cacheNames = CacheConstants.OPTION_KEY_PREFIX)
public class OptionServiceImpl implements OptionService { public class OptionServiceImpl implements OptionService {
private final OptionMapper baseMapper; private final OptionMapper baseMapper;
@ -55,13 +50,13 @@ public class OptionServiceImpl implements OptionService {
} }
@Override @Override
@CacheEvict(allEntries = true) // @CacheInvalidate(key = "#req.code", name = CacheConstants.OPTION_KEY_PREFIX, multi = true)
public void update(List<OptionReq> req) { public void update(List<OptionReq> req) {
baseMapper.updateBatchById(BeanUtil.copyToList(req, OptionDO.class)); baseMapper.updateBatchById(BeanUtil.copyToList(req, OptionDO.class));
} }
@Override @Override
@CacheEvict(allEntries = true) @CacheInvalidate(key = "#req.code", name = CacheConstants.OPTION_KEY_PREFIX, multi = true)
public void resetValue(OptionResetValueReq req) { public void resetValue(OptionResetValueReq req) {
baseMapper.lambdaUpdate().set(OptionDO::getValue, null).in(OptionDO::getCode, req.getCode()).update(); baseMapper.lambdaUpdate().set(OptionDO::getValue, null).in(OptionDO::getCode, req.getCode()).update();
} }

View File

@ -19,8 +19,8 @@ package top.charles7c.continew.admin.system.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alicp.jetcache.anno.CacheInvalidate;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import top.charles7c.continew.admin.auth.service.OnlineUserService; import top.charles7c.continew.admin.auth.service.OnlineUserService;
@ -78,7 +78,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
} }
@Override @Override
@CacheEvict(cacheNames = CacheConstants.MENU_KEY_PREFIX, key = "#req.code == 'admin' ? 'ALL' : #req.code") @CacheInvalidate(key = "#req.code == 'admin' ? 'ALL' : #req.code", name = CacheConstants.MENU_KEY_PREFIX)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(RoleReq req, Long id) { public void update(RoleReq req, Long id) {
String name = req.getName(); String name = req.getName();

View File

@ -20,12 +20,12 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.file.FileNameUtil; import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.x.file.storage.core.FileInfo; import org.dromara.x.file.storage.core.FileInfo;
import org.dromara.x.file.storage.core.FileStorageService; import org.dromara.x.file.storage.core.FileStorageService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -63,7 +63,6 @@ import java.util.Optional;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@CacheConfig(cacheNames = CacheConstants.USER_KEY_PREFIX)
public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserResp, UserDetailResp, UserQuery, UserReq> implements UserService, CommonUserService { public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserResp, UserDetailResp, UserQuery, UserReq> implements UserService, CommonUserService {
@Resource @Resource
@ -264,7 +263,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
} }
@Override @Override
@Cacheable(key = "#id") @Cached(key = "#id", cacheType = CacheType.BOTH, name = CacheConstants.USER_KEY_PREFIX)
public String getNicknameById(Long id) { public String getNicknameById(Long id) {
return baseMapper.selectNicknameById(id); return baseMapper.selectNicknameById(id);
} }

View File

@ -19,6 +19,7 @@ package top.charles7c.continew.admin;
import cn.dev33.satoken.annotation.SaIgnore; import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.alicp.jetcache.anno.config.EnableMethodCache;
import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Hidden;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -28,7 +29,6 @@ import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties; import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
@ -42,11 +42,11 @@ import java.net.InetAddress;
* @since 2022/12/8 23:15 * @since 2022/12/8 23:15
*/ */
@Slf4j @Slf4j
@EnableCaching
@EnableFileStorage
@RestController @RestController
@EnableFileStorage
@SpringBootApplication @SpringBootApplication
@RequiredArgsConstructor @RequiredArgsConstructor
@EnableMethodCache(basePackages = "top.charles7c.continew.admin")
public class ContiNewAdminApplication implements ApplicationRunner { public class ContiNewAdminApplication implements ApplicationRunner {
private final ProjectProperties projectProperties; private final ProjectProperties projectProperties;

View File

@ -67,7 +67,7 @@ public class AuthController {
@Operation(summary = "账号登录", description = "根据账号和密码进行登录认证") @Operation(summary = "账号登录", description = "根据账号和密码进行登录认证")
@PostMapping("/account") @PostMapping("/account")
public R<LoginResp> accountLogin(@Validated @RequestBody AccountLoginReq loginReq) { public R<LoginResp> accountLogin(@Validated @RequestBody AccountLoginReq loginReq) {
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, loginReq.getUuid()); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + loginReq.getUuid();
String captcha = RedisUtils.get(captchaKey); String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效"); ValidationUtils.throwIfBlank(captcha, "验证码已失效");
RedisUtils.delete(captchaKey); RedisUtils.delete(captchaKey);
@ -84,7 +84,7 @@ public class AuthController {
@PostMapping("/email") @PostMapping("/email")
public R<LoginResp> emailLogin(@Validated @RequestBody EmailLoginReq loginReq) { public R<LoginResp> emailLogin(@Validated @RequestBody EmailLoginReq loginReq) {
String email = loginReq.getEmail(); String email = loginReq.getEmail();
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, email); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + email;
String captcha = RedisUtils.get(captchaKey); String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效"); ValidationUtils.throwIfBlank(captcha, "验证码已失效");
ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, "验证码错误"); ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, "验证码错误");
@ -98,7 +98,7 @@ public class AuthController {
@PostMapping("/phone") @PostMapping("/phone")
public R<LoginResp> phoneLogin(@Validated @RequestBody PhoneLoginReq loginReq) { public R<LoginResp> phoneLogin(@Validated @RequestBody PhoneLoginReq loginReq) {
String phone = loginReq.getPhone(); String phone = loginReq.getPhone();
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, phone); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + phone;
String captcha = RedisUtils.get(captchaKey); String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效"); ValidationUtils.throwIfBlank(captcha, "验证码已失效");
ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, "验证码错误"); ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, "验证码错误");

View File

@ -16,20 +16,24 @@
package top.charles7c.continew.admin.webapi.common; package top.charles7c.continew.admin.webapi.common;
import java.time.Duration; import cn.dev33.satoken.annotation.SaIgnore;
import java.util.LinkedHashMap; import cn.hutool.core.lang.Dict;
import java.util.Map; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.servlet.JakartaServletUtil;
import com.anji.captcha.model.common.RepCodeEnum;
import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.wf.captcha.base.Captcha;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.mail.MessagingException; import jakarta.mail.MessagingException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Pattern;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.dromara.sms4j.api.SmsBlend; import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse; import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.comm.constant.SupplierConstant; import org.dromara.sms4j.comm.constant.SupplierConstant;
@ -38,20 +42,6 @@ import org.redisson.api.RateType;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.anji.captcha.model.common.RepCodeEnum;
import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.wf.captcha.base.Captcha;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.servlet.JakartaServletUtil;
import top.charles7c.continew.admin.common.config.properties.CaptchaProperties; import top.charles7c.continew.admin.common.config.properties.CaptchaProperties;
import top.charles7c.continew.admin.common.constant.CacheConstants; import top.charles7c.continew.admin.common.constant.CacheConstants;
import top.charles7c.continew.admin.common.constant.RegexConstants; import top.charles7c.continew.admin.common.constant.RegexConstants;
@ -66,6 +56,10 @@ import top.charles7c.continew.starter.extension.crud.model.resp.R;
import top.charles7c.continew.starter.log.common.annotation.Log; import top.charles7c.continew.starter.log.common.annotation.Log;
import top.charles7c.continew.starter.messaging.mail.util.MailUtils; import top.charles7c.continew.starter.messaging.mail.util.MailUtils;
import java.time.Duration;
import java.util.LinkedHashMap;
import java.util.Map;
/** /**
* 验证码 API * 验证码 API
* *
@ -106,7 +100,7 @@ public class CaptchaController {
public R<CaptchaResp> getImageCaptcha() { public R<CaptchaResp> getImageCaptcha() {
Captcha captcha = graphicCaptchaProperties.getCaptcha(); Captcha captcha = graphicCaptchaProperties.getCaptcha();
String uuid = IdUtil.fastUUID(); String uuid = IdUtil.fastUUID();
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, uuid); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + uuid;
RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaProperties.getExpirationInMinutes())); RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaProperties.getExpirationInMinutes()));
return R.ok(CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).build()); return R.ok(CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).build());
} }
@ -116,7 +110,7 @@ public class CaptchaController {
public R getMailCaptcha(@NotBlank(message = "邮箱不能为空") @Pattern(regexp = RegexConstants.EMAIL, message = "邮箱格式错误") String email) throws MessagingException { public R getMailCaptcha(@NotBlank(message = "邮箱不能为空") @Pattern(regexp = RegexConstants.EMAIL, message = "邮箱格式错误") String email) throws MessagingException {
String limitKeyPrefix = CacheConstants.LIMIT_KEY_PREFIX; String limitKeyPrefix = CacheConstants.LIMIT_KEY_PREFIX;
String captchaKeyPrefix = CacheConstants.CAPTCHA_KEY_PREFIX; String captchaKeyPrefix = CacheConstants.CAPTCHA_KEY_PREFIX;
String limitCaptchaKey = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix, email); String limitCaptchaKey = limitKeyPrefix + captchaKeyPrefix + email;
long limitTimeInMillisecond = RedisUtils.getTimeToLive(limitCaptchaKey); long limitTimeInMillisecond = RedisUtils.getTimeToLive(limitCaptchaKey);
CheckUtils.throwIf(limitTimeInMillisecond > 0, "发送验证码过于频繁,请您 {}s 后再试", limitTimeInMillisecond / 1000); CheckUtils.throwIf(limitTimeInMillisecond > 0, "发送验证码过于频繁,请您 {}s 后再试", limitTimeInMillisecond / 1000);
// 生成验证码 // 生成验证码
@ -129,7 +123,7 @@ public class CaptchaController {
.set("expiration", expirationInMinutes)); .set("expiration", expirationInMinutes));
MailUtils.sendHtml(email, String.format("【%s】邮箱验证码", projectProperties.getName()), content); MailUtils.sendHtml(email, String.format("【%s】邮箱验证码", projectProperties.getName()), content);
// 保存验证码 // 保存验证码
String captchaKey = RedisUtils.formatKey(captchaKeyPrefix, email); String captchaKey = captchaKeyPrefix + email;
RedisUtils.set(captchaKey, captcha, Duration.ofMinutes(expirationInMinutes)); RedisUtils.set(captchaKey, captcha, Duration.ofMinutes(expirationInMinutes));
RedisUtils.set(limitCaptchaKey, captcha, Duration.ofSeconds(captchaMail.getLimitInSeconds())); RedisUtils.set(limitCaptchaKey, captcha, Duration.ofSeconds(captchaMail.getLimitInSeconds()));
return R.ok(String.format("发送成功,验证码有效期 %s 分钟", expirationInMinutes)); return R.ok(String.format("发送成功,验证码有效期 %s 分钟", expirationInMinutes));
@ -148,21 +142,21 @@ public class CaptchaController {
String templateId = captchaSms.getTemplateId(); String templateId = captchaSms.getTemplateId();
String limitKeyPrefix = CacheConstants.LIMIT_KEY_PREFIX; String limitKeyPrefix = CacheConstants.LIMIT_KEY_PREFIX;
String captchaKeyPrefix = CacheConstants.CAPTCHA_KEY_PREFIX; String captchaKeyPrefix = CacheConstants.CAPTCHA_KEY_PREFIX;
String limitTemplateKeyPrefix = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix); String limitTemplateKeyPrefix = limitKeyPrefix + captchaKeyPrefix;
// 限制短信发送频率 // 限制短信发送频率
// 1.同一号码同一短信模板1分钟2条1小时8条24小时20条e.g. LIMIT:CAPTCHA:XXX:188xxxxx:1 // 1.同一号码同一短信模板1分钟2条1小时8条24小时20条e.g. LIMIT:CAPTCHA:XXX:188xxxxx:1
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils
.formatKey(limitTemplateKeyPrefix, "MIN", phone, templateId), RateType.OVERALL, 2, 60), "验证码发送过于频繁,请稍后后再试"); .formatKey(limitTemplateKeyPrefix + "MIN", phone, templateId), RateType.OVERALL, 2, 60), "验证码发送过于频繁,请稍后后再试");
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils
.formatKey(limitTemplateKeyPrefix, "HOUR", phone, templateId), RateType.OVERALL, 8, 60 * 60), "验证码发送过于频繁,请稍后后再试"); .formatKey(limitTemplateKeyPrefix + "HOUR", phone, templateId), RateType.OVERALL, 8, 60 * 60), "验证码发送过于频繁,请稍后后再试");
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils
.formatKey(limitTemplateKeyPrefix, "DAY", phone, templateId), RateType.OVERALL, 20, 60 * 60 * 24), "验证码发送过于频繁,请稍后后再试"); .formatKey(limitTemplateKeyPrefix + "DAY", phone, templateId), RateType.OVERALL, 20, 60 * 60 * 24), "验证码发送过于频繁,请稍后后再试");
// 2.同一号码所有短信模板 24 小时 100 e.g. LIMIT:CAPTCHA:188xxxxx // 2.同一号码所有短信模板 24 小时 100 e.g. LIMIT:CAPTCHA:188xxxxx
String limitPhoneKey = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix, phone); String limitPhoneKey = limitKeyPrefix + captchaKeyPrefix + phone;
CheckUtils.throwIf(!RedisUtils CheckUtils.throwIf(!RedisUtils
.rateLimit(limitPhoneKey, RateType.OVERALL, 100, 60 * 60 * 24), "验证码发送过于频繁,请稍后后再试"); .rateLimit(limitPhoneKey, RateType.OVERALL, 100, 60 * 60 * 24), "验证码发送过于频繁,请稍后后再试");
// 3.同一 IP 每分钟限制发送 30 e.g. LIMIT:CAPTCHA:PHONE:1xx.1xx.1xx.1xx // 3.同一 IP 每分钟限制发送 30 e.g. LIMIT:CAPTCHA:PHONE:1xx.1xx.1xx.1xx
String limitIpKey = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix, "PHONE", JakartaServletUtil String limitIpKey = RedisUtils.formatKey(limitKeyPrefix + captchaKeyPrefix + "PHONE", JakartaServletUtil
.getClientIP(request)); .getClientIP(request));
CheckUtils.throwIf(!RedisUtils.rateLimit(limitIpKey, RateType.OVERALL, 30, 60), "验证码发送过于频繁,请稍后后再试"); CheckUtils.throwIf(!RedisUtils.rateLimit(limitIpKey, RateType.OVERALL, 30, 60), "验证码发送过于频繁,请稍后后再试");
// 生成验证码 // 生成验证码
@ -177,7 +171,7 @@ public class CaptchaController {
.getTemplateId(), (LinkedHashMap<String, String>)messageMap); .getTemplateId(), (LinkedHashMap<String, String>)messageMap);
CheckUtils.throwIf(!smsResponse.isSuccess(), "验证码发送失败"); CheckUtils.throwIf(!smsResponse.isSuccess(), "验证码发送失败");
// 保存验证码 // 保存验证码
String captchaKey = RedisUtils.formatKey(captchaKeyPrefix, phone); String captchaKey = captchaKeyPrefix + phone;
RedisUtils.set(captchaKey, captcha, Duration.ofMinutes(expirationInMinutes)); RedisUtils.set(captchaKey, captcha, Duration.ofMinutes(expirationInMinutes));
return R.ok(String.format("发送成功,验证码有效期 %s 分钟", expirationInMinutes)); return R.ok(String.format("发送成功,验证码有效期 %s 分钟", expirationInMinutes));
} }

View File

@ -20,6 +20,7 @@ import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.tree.Tree; import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ClassUtil; import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alicp.jetcache.anno.Cached;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.enums.ParameterIn;
@ -27,7 +28,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.x.file.storage.core.FileInfo; import org.dromara.x.file.storage.core.FileInfo;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -103,7 +103,7 @@ public class CommonController {
@Operation(summary = "查询字典", description = "查询字典列表") @Operation(summary = "查询字典", description = "查询字典列表")
@Parameter(name = "code", description = "字典编码", example = "announcement_type", in = ParameterIn.PATH) @Parameter(name = "code", description = "字典编码", example = "announcement_type", in = ParameterIn.PATH)
@GetMapping("/dict/{code}") @GetMapping("/dict/{code}")
@Cacheable(key = "#code", cacheNames = CacheConstants.DICT_KEY_PREFIX) @Cached(key = "#code", name = CacheConstants.DICT_KEY_PREFIX)
public R<List<LabelValueResp>> listDict(@PathVariable String code) { public R<List<LabelValueResp>> listDict(@PathVariable String code) {
Optional<Class<?>> enumClass = this.getEnumClassByName(code); Optional<Class<?>> enumClass = this.getEnumClassByName(code);
return R.ok(enumClass.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code))); return R.ok(enumClass.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code)));
@ -112,7 +112,7 @@ public class CommonController {
@SaIgnore @SaIgnore
@Operation(summary = "查询参数", description = "查询参数") @Operation(summary = "查询参数", description = "查询参数")
@GetMapping("/option") @GetMapping("/option")
@Cacheable(cacheNames = CacheConstants.OPTION_KEY_PREFIX) @Cached(name = CacheConstants.OPTION_KEY_PREFIX)
public R<List<LabelValueResp>> listOption(@Validated OptionQuery query) { public R<List<LabelValueResp>> listOption(@Validated OptionQuery query) {
return R.ok(optionService.list(query) return R.ok(optionService.list(query)
.stream() .stream()

View File

@ -113,7 +113,7 @@ public class UserCenterController {
String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
.getCurrentPassword())); .getCurrentPassword()));
ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败"); ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败");
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, updateReq.getNewPhone()); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + updateReq.getNewPhone();
String captcha = RedisUtils.get(captchaKey); String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效"); ValidationUtils.throwIfBlank(captcha, "验证码已失效");
ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误"); ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误");
@ -128,7 +128,7 @@ public class UserCenterController {
String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
.getCurrentPassword())); .getCurrentPassword()));
ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败"); ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败");
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, updateReq.getNewEmail()); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + updateReq.getNewEmail();
String captcha = RedisUtils.get(captchaKey); String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效"); ValidationUtils.throwIfBlank(captcha, "验证码已失效");
ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误"); ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误");

View File

@ -56,30 +56,54 @@ spring.liquibase:
change-log: classpath:/db/changelog/db.changelog-master.yaml change-log: classpath:/db/changelog/db.changelog-master.yaml
--- ### 缓存配置 --- ### 缓存配置
spring: spring.data:
## Spring Cache 配置 ## Redis 配置(单机模式)
cache: redis:
type: REDIS # 地址
data: host: ${REDIS_HOST:127.0.0.1}
## Redis 配置(单机版) # 端口(默认 6379
redis: port: ${REDIS_PORT:6379}
# 地址 # 密码(未设置密码时可为空或注释掉)
host: ${REDIS_HOST:127.0.0.1} password: ${REDIS_PWD:123456}
# 端口(默认 6379 # 数据库索引
port: ${REDIS_PORT:6379} database: ${REDIS_DB:0}
# 密码(未设置密码时可为空或注释掉) # 连接超时时间
password: ${REDIS_PWD:123456} timeout: 10s
# 数据库索引 # 是否开启 SSL
database: ${REDIS_DB:0} ssl:
# 连接超时时间 enabled: false
timeout: 10s ## Redisson 配置
# 是否开启 SSL redisson:
ssl: enabled: true
enabled: false mode: SINGLE
# Redisson 配置 ## JetCache 配置
redisson: jetcache:
enabled: true ## 本地/进程级/一级缓存配置
mode: SINGLE local:
default:
# 缓存类型
type: caffeine
# key 转换器的全局配置
keyConvertor: jackson
# 以毫秒为单位指定超时时间的全局配置
expireAfterWriteInMillis: 7200000
# 每个缓存实例的最大元素的全局配置,仅 local 类型的缓存需要指定
limit: 1000
## 远程/分布式/二级缓存配置
remote:
default:
# 缓存类型
type: redisson
# key 转换器的全局配置(用于将复杂的 KEY 类型转换为缓存实现可以接受的类型)
keyConvertor: jackson
# 以毫秒为单位指定超时时间的全局配置
expireAfterWriteInMillis: 7200000
# 2.7+ 支持两级缓存更新以后失效其他 JVM 中的 local cache但多个服务共用 Redis 同一个 channel 可能会造成广播风暴需要在这里指定channel。
# 你可以决定多个不同的服务是否共用同一个 channel如果没有指定则不开启。
broadcastChannel: ${spring.application.name}
# 序列化器的全局配置,仅 remote 类型的缓存需要指定
valueEncoder: java
valueDecoder: java
--- ### 验证码配置 --- ### 验证码配置
continew-starter.captcha: continew-starter.captcha:

View File

@ -58,30 +58,54 @@ spring.liquibase:
change-log: classpath:/db/changelog/db.changelog-master.yaml change-log: classpath:/db/changelog/db.changelog-master.yaml
--- ### 缓存配置 --- ### 缓存配置
spring: spring.data:
## Spring Cache 配置 ## Redis 配置(单机模式)
cache: redis:
type: REDIS # 地址
data: host: ${REDIS_HOST:127.0.0.1}
## Redis 配置(单机版) # 端口(默认 6379
redis: port: ${REDIS_PORT:6379}
# 地址 # 密码(未设置密码时可为空或注释掉)
host: ${REDIS_HOST:127.0.0.1} password: ${REDIS_PWD:123456}
# 端口(默认 6379 # 数据库索引
port: ${REDIS_PORT:6379} database: ${REDIS_DB:0}
# 密码(未设置密码时可为空或注释掉) # 连接超时时间
password: ${REDIS_PWD:123456} timeout: 10s
# 数据库索引 # 是否开启 SSL
database: ${REDIS_DB:0} ssl:
# 连接超时时间 enabled: false
timeout: 10s ## Redisson 配置
# 是否开启 SSL redisson:
ssl: enabled: true
enabled: false mode: SINGLE
# Redisson 配置 ## JetCache 配置
redisson: jetcache:
enabled: true ## 本地/进程级/一级缓存配置
mode: SINGLE local:
default:
# 缓存类型
type: caffeine
# key 转换器的全局配置
keyConvertor: jackson
# 以毫秒为单位指定超时时间的全局配置
expireAfterWriteInMillis: 7200000
# 每个缓存实例的最大元素的全局配置,仅 local 类型的缓存需要指定
limit: 1000
## 远程/分布式/二级缓存配置
remote:
default:
# 缓存类型
type: redisson
# key 转换器的全局配置(用于将复杂的 KEY 类型转换为缓存实现可以接受的类型)
keyConvertor: jackson
# 以毫秒为单位指定超时时间的全局配置
expireAfterWriteInMillis: 7200000
# 2.7+ 支持两级缓存更新以后失效其他 JVM 中的 local cache但多个服务共用 Redis 同一个 channel 可能会造成广播风暴需要在这里指定channel。
# 你可以决定多个不同的服务是否共用同一个 channel如果没有指定则不开启。
broadcastChannel: ${spring.application.name}
# 序列化器的全局配置,仅 remote 类型的缓存需要指定
valueEncoder: java
valueDecoder: java
--- ### 验证码配置 --- ### 验证码配置
continew-starter.captcha: continew-starter.captcha: