perf: 优化用户缓存管理,统一转换为小写

close https://github.com/elunez/eladmin/issues/866
pull/875/head
Jie Zheng 2025-01-21 15:20:02 +08:00
parent db63c953d4
commit 31b033afe8
1 changed files with 6 additions and 0 deletions

View File

@ -44,6 +44,8 @@ public class UserCacheManager {
* @return JwtUserDto * @return JwtUserDto
*/ */
public JwtUserDto getUserCache(String userName) { public JwtUserDto getUserCache(String userName) {
// 转小写
userName = StringUtils.lowerCase(userName);
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
// 获取数据 // 获取数据
return redisUtils.get(LoginProperties.cacheKey + userName, JwtUserDto.class); return redisUtils.get(LoginProperties.cacheKey + userName, JwtUserDto.class);
@ -57,6 +59,8 @@ public class UserCacheManager {
*/ */
@Async @Async
public void addUserCache(String userName, JwtUserDto user) { public void addUserCache(String userName, JwtUserDto user) {
// 转小写
userName = StringUtils.lowerCase(userName);
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
// 添加数据, 避免数据同时过期 // 添加数据, 避免数据同时过期
long time = idleTime + RandomUtil.randomInt(900, 1800); long time = idleTime + RandomUtil.randomInt(900, 1800);
@ -71,6 +75,8 @@ public class UserCacheManager {
*/ */
@Async @Async
public void cleanUserCache(String userName) { public void cleanUserCache(String userName) {
// 转小写
userName = StringUtils.lowerCase(userName);
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
// 清除数据 // 清除数据
redisUtils.del(LoginProperties.cacheKey + userName); redisUtils.del(LoginProperties.cacheKey + userName);