|
|
|
@ -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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>
|
|
|
|
|
* 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 최초 생성
|
|
|
|
|
*
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* @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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|