mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
优先使用本地缓存
This commit is contained in:
@@ -34,6 +34,7 @@ public class RedisApiManagerImpl extends LocalApiManagerImpl {
|
||||
}
|
||||
|
||||
protected ApiInfoDTO cache(ApiInfo apiInfo) {
|
||||
super.cache(apiInfo);
|
||||
String key = apiInfo.getApiName() + apiInfo.getApiVersion();
|
||||
ApiInfoDTO apiInfoDTO = CopyUtil.copyBean(apiInfo, ApiInfoDTO::new);
|
||||
stringRedisTemplate.opsForHash().put(KEY_API, key, JsonUtil.toJSONString(apiInfoDTO));
|
||||
@@ -43,6 +44,10 @@ public class RedisApiManagerImpl extends LocalApiManagerImpl {
|
||||
|
||||
@Override
|
||||
public ApiInfoDTO get(String apiName, String apiVersion) {
|
||||
ApiInfoDTO apiInfoDTO = super.get(apiName, apiVersion);
|
||||
if (apiInfoDTO != null) {
|
||||
return apiInfoDTO;
|
||||
}
|
||||
String key = apiName + apiVersion;
|
||||
try {
|
||||
BoundHashOperations<String, String, String> operations = stringRedisTemplate.boundHashOps(KEY_API);
|
||||
|
@@ -35,6 +35,10 @@ public class RedisIsvApiPermissionManagerImpl extends LocalIsvApiPermissionManag
|
||||
|
||||
@Override
|
||||
public boolean doCheck(Long isvId, ApiInfoDTO apiInfoDTO) {
|
||||
boolean check = super.doCheck(isvId, apiInfoDTO);
|
||||
if (check) {
|
||||
return true;
|
||||
}
|
||||
BoundHashOperations<String, String, String> operations = stringRedisTemplate.boundHashOps(CACHE_KEY);
|
||||
String value = operations.get(String.valueOf(isvId));
|
||||
if (Objects.equals(value, SopConstants.NULL)) {
|
||||
@@ -53,6 +57,7 @@ public class RedisIsvApiPermissionManagerImpl extends LocalIsvApiPermissionManag
|
||||
|
||||
@Override
|
||||
protected void cache(Long isvId, List<Long> apiIdList) {
|
||||
super.cache(isvId, apiIdList);
|
||||
stringRedisTemplate.opsForHash().put(CACHE_KEY, String.valueOf(isvId), JsonUtil.toJSONString(apiIdList));
|
||||
log.info("更新isv接口id redis缓存, isvId={}, apiIdList={}", isvId, apiIdList);
|
||||
}
|
||||
|
@@ -29,6 +29,10 @@ public class RedisIsvManagerImpl extends LocalIsvManagerImpl {
|
||||
|
||||
@Override
|
||||
public IsvDTO getIsv(String appId) {
|
||||
IsvDTO isv = super.getIsv(appId);
|
||||
if (isv != null) {
|
||||
return isv;
|
||||
}
|
||||
try {
|
||||
Object value = stringRedisTemplate.opsForHash().get(KEY_ISV, appId);
|
||||
if (Objects.equals(value, SopConstants.NULL)) {
|
||||
@@ -47,6 +51,7 @@ public class RedisIsvManagerImpl extends LocalIsvManagerImpl {
|
||||
|
||||
@Override
|
||||
protected void cache(String appId, IsvDTO isvDTO) {
|
||||
super.cache(appId, isvDTO);
|
||||
stringRedisTemplate.opsForHash().put(KEY_ISV, appId, JsonUtil.toJSONString(isvDTO));
|
||||
log.debug("更新isv redis缓存, isvDTO={}", isvDTO);
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import com.gitee.sop.support.constant.SopConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Collections;
|
||||
@@ -26,6 +27,10 @@ public class RedisSecretManager extends LocalSecretManagerImpl {
|
||||
|
||||
@Override
|
||||
public String getIsvPublicKey(Long isvId) {
|
||||
String isvPublicKey = super.getIsvPublicKey(isvId);
|
||||
if (StringUtils.hasText(isvPublicKey)) {
|
||||
return isvPublicKey;
|
||||
}
|
||||
try {
|
||||
Object value = stringRedisTemplate.opsForHash().get(KEY_SEC, buildHashKey(isvId));
|
||||
if (Objects.equals(value, SopConstants.NULL)) {
|
||||
@@ -47,6 +52,7 @@ public class RedisSecretManager extends LocalSecretManagerImpl {
|
||||
if (publicKey == null) {
|
||||
publicKey = SopConstants.NULL;
|
||||
}
|
||||
super.cache(isvId, publicKey);
|
||||
stringRedisTemplate.opsForHash().put(KEY_SEC, buildHashKey(isvId), publicKey);
|
||||
log.debug("更新isv秘钥redis缓存, isvId={}", isvId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user