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,26 +1,26 @@
<?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">
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.xit.core.biz.mapper.IAuthApiMapper">
<!-- 일반 로그인 -->
<select id="actionLogin" resultType="egovframework.com.cmm.LoginVO">
<if test="userSe = 'USR'">
/** auth-mysql-mapper|actionLogin-로그인|julim */
SELECT user_id AS id
, user_nm AS name
, password
, ihidnum
, email_adres AS email
, 'USR' AS userSe
, orgnzt_id
, esntl_id
FROM xit_user_info
WHERE user_id = #{id}
AND password = #{password}
AND user_sttus_code = 'P'
</if>
</select>
<!-- 일반 로그인 -->
<select id="actionLogin" resultType="egovframework.com.cmm.LoginVO">
<if test="userSe = 'USR'">
/** auth-mysql-mapper|actionLogin-로그인|julim */
SELECT user_id AS id
, user_nm AS name
, password
, ihidnum
, email_adres AS email
, 'USR' AS userSe
, orgnzt_id
, esntl_id
FROM xit_user_info
WHERE user_id = #{id}
AND password = #{password}
AND user_sttus_code = 'P'
</if>
</select>
</mapper>

@ -1,43 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.xit.core.biz.mapper.ILoggingMapper">
<insert id="saveLogging" parameterType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|saveLogging|julim */
INSERT INTO tb_cmm_api_log (
request_id
, system_id
, req_system_id
, method
, uri
, param
, ip
, access_token
, session_id
, success
, response
, message
, regist_dt
, regist_id
) VALUES (
#{requestId}
, #{systemId}
, #{reqSystemId}
, #{method}
, #{uri}
, #{param}
, #{ip}
, #{accessToken}
, #{sessionId}
, #{success}
, #{response}
, #{message}
, now(3)
, #{registId}
)
</insert>
<insert id="saveLogging" parameterType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|saveLogging|julim */
INSERT INTO tb_cmm_api_log (
request_id
, system_id
, req_system_id
, method
, uri
, param
, ip
, access_token
, session_id
, success
, response
, message
, regist_dt
, regist_id
) VALUES (
#{requestId}
, #{systemId}
, #{reqSystemId}
, #{method}
, #{uri}
, #{param}
, #{ip}
, #{accessToken}
, #{sessionId}
, #{success}
, #{response}
, #{message}
, now(3)
, #{registId}
)
</insert>
<update id="updateLogging" parameterType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|updateLogging|julim */

Loading…
Cancel
Save