perf:移除TimedCacheService、TimedCacheHelper,新增TsCacheService,同时实现了内存缓存、Redis缓存

This commit is contained in:
曾文豪
2024-07-25 17:35:01 +08:00
parent d357fa7c85
commit 8ea34c3ee0
14 changed files with 267 additions and 132 deletions

View File

@@ -8,8 +8,8 @@ import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SM4;
import com.tiesheng.util.ServletKit;
import com.tiesheng.util.TimedCacheHelper;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.service.TsCacheService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@@ -104,12 +104,12 @@ public class EncryptConfig {
String salt = decrypt(encrypted).substring(0, saltSize);
String inputEncrypted = passwdCreate(inputPasswd, salt);
if (!StrUtil.equals(inputEncrypted, encrypted)) {
String clientIp = ServletKit.getClientIP();
int num = NumberUtil.parseInt(TimedCacheHelper.getTimedCache().get(clientIp, false));
String clientIp = "passwdVerify_" + ServletKit.getClientIP();
int num = NumberUtil.parseInt(TsCacheService.of().get(clientIp, -1));
if (num > 5) {
throw new ApiException("登录失败已达6次请10分钟后再试");
}
TimedCacheHelper.getTimedCache().put(clientIp, String.valueOf(num + 1), 10 * 60 * 1000);
TsCacheService.of().put(clientIp, String.valueOf(num + 1), 10 * 60 * 1000);
throw new ApiException("账号或密码错误");
}
}