From cbfeeac158b5fadf38086f18b1d1243ff98fcfcc Mon Sep 17 00:00:00 2001 From: limju Date: Fri, 13 Oct 2023 18:16:13 +0900 Subject: [PATCH] fix: CacheKeyGenerator fix --- .../biz/nice/service/BizNiceCiService.java | 1 + .../config/cache/CacheKeyGenerator.java | 37 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/mens-api/src/main/java/kr/xit/biz/nice/service/BizNiceCiService.java b/mens-api/src/main/java/kr/xit/biz/nice/service/BizNiceCiService.java index 20ba336..699cfc5 100644 --- a/mens-api/src/main/java/kr/xit/biz/nice/service/BizNiceCiService.java +++ b/mens-api/src/main/java/kr/xit/biz/nice/service/BizNiceCiService.java @@ -109,6 +109,7 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic * @return * */ + @Transactional @Override public TokenRevokeResponse revokeToken(final NiceCiRequest reqDTO){ TokenRevokeResponse resDTO = niceCiService.revokeToken(reqDTO); diff --git a/mens-core/src/main/java/kr/xit/core/spring/config/cache/CacheKeyGenerator.java b/mens-core/src/main/java/kr/xit/core/spring/config/cache/CacheKeyGenerator.java index 0e7472d..b9e9471 100644 --- a/mens-core/src/main/java/kr/xit/core/spring/config/cache/CacheKeyGenerator.java +++ b/mens-core/src/main/java/kr/xit/core/spring/config/cache/CacheKeyGenerator.java @@ -1,14 +1,17 @@ package kr.xit.core.spring.config.cache; -import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.cache.interceptor.SimpleKeyGenerator; - import java.lang.reflect.Method; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.cache.interceptor.SimpleKey; /** *
  * description : Cache key Generator
  *               -> cache method parmeter -> key로 Generator
+ *             - params가 String... 형태인 경우 - method(String arg1, String arg2)
+ *               -> arg1="", arg2="" 형태로 생성
+ *             - params가 Object class 인 경우 - method(DTO class)
+ *               -> [필드값, 필드값] 형태로 생성
  * packageName : kr.xit.core.spring.config.cache
  * fileName    : CacheKeyGenerator
  * author      : limju
@@ -19,16 +22,30 @@ import java.lang.reflect.Method;
  * 2023-09-06    limju       최초 생성
  *
  * 
+ * * @see CacheType * @see CachingConfig */ public class CacheKeyGenerator implements KeyGenerator { - @Override - public Object generate(Object target, Method method, Object... params) { - final StringBuilder keyBuilder = new StringBuilder(); - keyBuilder.append(method.getName()); - keyBuilder.append(SimpleKeyGenerator.generateKey(params)); - return keyBuilder.toString(); - } + @Override + public Object generate(Object target, Method method, Object... params) { + if(params.length == 0) { + return SimpleKey.EMPTY; + } + + // params가 String... 형태인 경우: method(String arg1, String arg2) + // -> arg1="", arg2="" 형태로 생성 + if(params.length == 1) { + Object param = params[0]; + if(param != null && !param.getClass().isArray()) { + return param; + } + } + + // params가 Object 인 경우: method(DTO class) + // -> [필드값, 필드값] 형태로 생성 + SimpleKey simpleKey = new SimpleKey(params); + return simpleKey; + } }