feat: cache(CaffeineCache) API 적용

dev
gitea-관리자 1 year ago
parent dccf7a2fb7
commit cf963cd135

@ -0,0 +1,16 @@
package kr.xit.core.spring.config;
import java.lang.reflect.Method;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
public class CacheKeyGenerator implements KeyGenerator {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(method.getName());
keyBuilder.append(SimpleKeyGenerator.generateKey(params));
return keyBuilder.toString();
}
}

@ -0,0 +1,26 @@
package kr.xit.core.spring.config;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum CacheType {
NICE_CRTF("niceCrtfInfo", 60 * 60 * 24, 1),
;
/**
*
*/
private final String cacheName;
/**
*
*/
private final int expireAfterWrite;
/**
*
*/
private final int maximumSize;
}

@ -0,0 +1,86 @@
package kr.xit.core.spring.config;
import com.github.benmanes.caffeine.cache.RemovalCause;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
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.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.benmanes.caffeine.cache.Caffeine;
/**
*
* initialCapacity: .
* maximumSize: .
* maximumWeight: .
* expireAfterAccess: , .
* expireAfterWrite: .
* refreshAfterWrite: .
* weakKeys: weak reference . (GC )
* weakValues: Value weak reference . (GC )
* softValues: Value soft reference . ( GC )
* recordStats: Statics .
*
*
*
* expireAfterWrite expireAfterAccess , expireAfterWrite .
* maximumSize maximumWeight .
*/
@Slf4j
@EnableCaching
@Configuration
public class CachingConfig {
/**
* <pre>
* initialCapacity: .
* maximumSize: .
* maximumWeight: .
* expireAfterAccess: , .
* expireAfterWrite: .
* refreshAfterWrite: .
* weakKeys: weak reference . (GC )
* weakValues: Value weak reference . (GC )
* softValues: Value soft reference . ( GC )
* recordStats: Statics .
*
*
*
* expireAfterWrite expireAfterAccess , expireAfterWrite .
* maximumSize maximumWeight .
* </pre>
*/
@Bean
public CacheManager cacheManager() {
List<CaffeineCache> caffeineCaches = Arrays.stream(CacheType.values())
.map(cache -> new CaffeineCache(
cache.getCacheName(),
Caffeine.newBuilder()
.recordStats()
.expireAfterWrite(cache.getExpireAfterWrite(), TimeUnit.SECONDS)
.maximumSize(cache.getMaximumSize())
.evictionListener((Object key, Object value, RemovalCause cause) ->
log.info("Key {} was evicted ({}): {}", key, cause, value))
.build()
))
.collect(Collectors.toList());
final SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(caffeineCaches);
return cacheManager;
}
@Bean
public KeyGenerator cacheKeyGenerator() {
return new CacheKeyGenerator();
}
}

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.xit.ens.support.cmm.mapper.ICmmEnsMapper">
<select id="selectNiceCrtfInfo" resultType="kr.xit.biz.ens.model.nice.NiceCiDTO$CrtfInfo">
/** ens-cmm-mysql-mapper|selectNiceCrtfInfo-Nice인증정보조회|julim */
SELECT signgu_code,
ffnlg_code,
client_id,
client_secret,
product_id,
access_token,
expires_in,
token_type,
scope,
site_code,
key_version,
public_key,
valid_dtim,
timestampdiff(DAY, '20230911235959', now()) AS remainingDays /* 잔여일수-공용키 */
FROM tb_cmm_nice_instn_crtf_info
WHERE signgu_code = #{signguCode}
AND ffnlg_code = #{ffnlgCode}
AND client_id = #{clientId}
</select>
<update id="updateNiceCrtfPublickey">
/** ens-cmm-mysql-mapper|updateNiceCrtfPublickey-Nice publickey 인증정보 갱신|julim */
UPDATE tb_cmm_nice_instn_crtf_info
SET site_code = #{siteCode},
key_version = #{keyVersion},
public_key = #{publicKey},
valid_dtim = #{validDtim},
updt_dt = now(),
updusr = #{updusr}
WHERE signgu_code = #{signguCode}
AND ffnlg_code = #{ffnlgCode}
AND client_id = #{clientId}
</update>
</mapper>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.xit.core.biz.mapper.IAuthApiMapper">
<!-- 일반 로그인 -->

Loading…
Cancel
Save