fix: CacheKeyGenerator SimpleKeyGenerator로 변경

dev
Jonguk. Lim 1 year ago
parent cbfeeac158
commit 4f3eae2e02

@ -6,7 +6,6 @@ import kr.xit.biz.cmm.mapper.ICmmEnsCacheMapper;
import kr.xit.biz.ens.model.cmm.CmmEnsRequestDTO;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.nice.NiceCiDTO.NiceCiInfo;
import kr.xit.core.spring.config.cache.CacheKeyGenerator;
import kr.xit.core.spring.config.cache.CacheType;
import kr.xit.core.spring.config.cache.CachingConfig;
import lombok.RequiredArgsConstructor;
@ -34,8 +33,8 @@ import org.springframework.transaction.annotation.Transactional;
*
* </pre>
* @see CacheType
* @see CacheKeyGenerator
* @see CachingConfig
* @see org.springframework.cache.interceptor.SimpleKeyGenerator
*/
@Slf4j
@RequiredArgsConstructor
@ -50,7 +49,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @return CrtfInfo
*/
@Transactional(readOnly = true)
@Cacheable(cacheNames = "niceCiInfo", keyGenerator = "cacheKeyGenerator")
@Cacheable(cacheNames = "niceCiInfo", keyGenerator = "simpleKeyGenerator")
public NiceCiInfo getNiceCiInfoCache(final String signguCode, final String ffnlgCode) {
return cmmEnsMapper.selectNiceCiInfo(signguCode, ffnlgCode);
}
@ -61,7 +60,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @param ffnlgCode
*/
@Transactional(readOnly = true)
@CacheEvict(cacheNames = "niceCiInfo", keyGenerator = "cacheKeyGenerator")
@CacheEvict(cacheNames = "niceCiInfo", keyGenerator = "simpleKeyGenerator")
public void removeNiceCiInfoCache(final String signguCode, final String ffnlgCode) {
}
@ -72,7 +71,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @return CmmEnsRlaybsnmDTO
*/
@Transactional(readOnly = true)
@Cacheable(cacheNames = "rlaybsnmInfo", keyGenerator = "cacheKeyGenerator")
@Cacheable(cacheNames = "rlaybsnmInfo", keyGenerator = "simpleKeyGenerator")
public CmmEnsRlaybsnmDTO getRlaybsnmInfoCache(final CmmEnsRequestDTO dto) {
return cmmEnsMapper.selectEnsRlaybsnmInfo(dto);
}
@ -83,7 +82,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @param ffnlgCode
*/
@Transactional(readOnly = true)
@CacheEvict(cacheNames = "rlaybsnmInfo", keyGenerator = "cacheKeyGenerator")
@CacheEvict(cacheNames = "rlaybsnmInfo", keyGenerator = "simpleKeyGenerator")
public void removeRlaybsnmInfoCache(final CmmEnsRequestDTO dto) {
}

@ -5,7 +5,6 @@ import com.github.benmanes.caffeine.cache.stats.CacheStats;
import kr.xit.biz.cmm.mapper.ICmmEnsCacheMapper;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.nice.NiceCiDTO.NiceCiInfo;
import kr.xit.core.spring.config.cache.CacheKeyGenerator;
import kr.xit.core.spring.config.cache.CacheType;
import kr.xit.core.spring.config.cache.CachingConfig;
import lombok.RequiredArgsConstructor;
@ -50,7 +49,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @return CrtfInfo
*/
@Transactional(readOnly = true)
@Cacheable(cacheNames = "niceCiInfo", keyGenerator = "cacheKeyGenerator")
@Cacheable(cacheNames = "niceCiInfo", keyGenerator = "simpleKeyGenerator")
public NiceCiInfo getNiceCiInfoCache(final String signguCode, final String ffnlgCode) {
return cmmEnsMapper.selectNiceCiInfo(NiceCiInfo.builder()
.signguCode(signguCode)
@ -64,7 +63,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @param ffnlgCode
*/
@Transactional(readOnly = true)
@CacheEvict(cacheNames = "niceCiInfo", keyGenerator = "cacheKeyGenerator")
@CacheEvict(cacheNames = "niceCiInfo", keyGenerator = "simpleKeyGenerator")
public void removeNiceCiInfoCache(final String signguCode, final String ffnlgCode) {
}
@ -75,7 +74,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @return CmmEnsRlaybsnmDTO
*/
@Transactional(readOnly = true)
@Cacheable(cacheNames = "rlaybsnmInfo", keyGenerator = "cacheKeyGenerator")
@Cacheable(cacheNames = "rlaybsnmInfo", keyGenerator = "simpleKeyGenerator")
public CmmEnsRlaybsnmDTO getRlaybsnmInfoCache(final String signguCode, final String ffnlgCode) {
return cmmEnsMapper.selectEnsRlaybsnmInfo(
CmmEnsRlaybsnmDTO.builder()
@ -91,7 +90,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @param ffnlgCode
*/
@Transactional(readOnly = true)
@CacheEvict(cacheNames = "rlaybsnmInfo", keyGenerator = "cacheKeyGenerator")
@CacheEvict(cacheNames = "rlaybsnmInfo", keyGenerator = "simpleKeyGenerator")
public void removeRlaybsnmInfoCache(final String signguCode, final String ffnlgCode) {
}

@ -1,51 +0,0 @@
package kr.xit.core.spring.config.cache;
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
* date : 2023-09-06
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-06 limju
*
* </pre>
*
* @see CacheType
* @see CachingConfig
*/
public class CacheKeyGenerator implements KeyGenerator {
@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;
}
}

@ -2,6 +2,7 @@ package kr.xit.core.spring.config.cache;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
/**
* <pre>
@ -17,7 +18,7 @@ import lombok.Getter;
* 2023-09-06 limju
*
* </pre>
* @see CacheKeyGenerator
* @see SimpleKeyGenerator
* @see CachingConfig
*/
@Getter

@ -7,6 +7,7 @@ import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -30,7 +31,7 @@ import java.util.stream.Collectors;
*
* </pre>
* @see CacheType
* @see CacheKeyGenerator
* @see SimpleKeyGenerator
*/
@Slf4j
@EnableCaching
@ -75,7 +76,7 @@ public class CachingConfig {
}
@Bean
public KeyGenerator cacheKeyGenerator() {
return new CacheKeyGenerator();
public KeyGenerator simpleKeyGenerator() {
return new SimpleKeyGenerator();
}
}

Loading…
Cancel
Save