调整缓存时间

master
ShiChangzhou 2 days ago
parent 29e59c06be
commit 07496ff556

@ -97,7 +97,7 @@ public class SysLoginService {
passwordService.validate(user, password);
// 缓存用户工厂数据源
redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, userInfo.getPoolName(),
CacheConstants.REFRESH_TIME, TimeUnit.MINUTES);
CacheConstants.EXPIRATION, TimeUnit.MINUTES);
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
return userInfo;
}

@ -3,9 +3,12 @@ package com.op.common.security.service;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.op.common.core.constant.CacheConstants;
import com.op.common.core.constant.SecurityConstants;
import com.op.common.core.utils.JwtUtils;
@ -31,7 +34,7 @@ public class TokenService {
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
private final static long expireTime = CacheConstants.EXPIRATION;
// private final static long expireTime = CacheConstants.EXPIRATION;
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
@ -59,7 +62,7 @@ public class TokenService {
// 接口返回信息
Map<String, Object> rspMap = new HashMap<String, Object>();
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
rspMap.put("expires_in", expireTime);
rspMap.put("expires_in", CacheConstants.EXPIRATION);
return rspMap;
}
@ -140,15 +143,16 @@ public class TokenService {
*/
public void refreshToken(LoginUser loginUser) {
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
loginUser.setExpireTime(loginUser.getLoginTime() + CacheConstants.EXPIRATION * MILLIS_MINUTE);
// 根据uuid将loginUser缓存
String userKey = getTokenKey(loginUser.getToken());
redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
redisService.setCacheObject(userKey, loginUser, CacheConstants.EXPIRATION, TimeUnit.MINUTES);
String username = loginUser.getUsername();
// 重置过期时间
String pool = redisService.getCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username);
redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, pool, expireTime, TimeUnit.MINUTES);
redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, pool, CacheConstants.EXPIRATION,
TimeUnit.MINUTES);
}
private String getTokenKey(String token) {

@ -368,7 +368,7 @@ public class SysUserController extends BaseController {
String username = SecurityUtils.getUsername();
// 缓存用户工厂数据源
redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, user.getPoolName(),
CacheConstants.REFRESH_TIME, TimeUnit.MINUTES);
CacheConstants.EXPIRATION, TimeUnit.MINUTES);
return success();
}

Loading…
Cancel
Save