-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MOA-498] 윈큐브의 AccessToken 캐시하여 사용 (#112)
- Loading branch information
1 parent
1ac2306
commit 18f5b44
Showing
5 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
spring: | ||
profiles: | ||
active: local | ||
|
||
application: | ||
type: api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
spring: | ||
profiles: | ||
active: local | ||
|
||
application: | ||
type: batch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/java/moa/global/config/cache/CacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package moa.global.config.cache; | ||
|
||
import static org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair; | ||
|
||
import java.time.Duration; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
import org.springframework.data.redis.cache.RedisCacheManager; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@EnableCaching | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class CacheConfig { | ||
|
||
public static final String WINCUBE_ACCESS_TOKEN_CACHE_NAME = "wincubeAccessToken"; | ||
public static final String WINCUBE_ACCESS_TOKEN_CACHE_MANAGER_NAME = "wincubeAccessTokenCacheManager"; | ||
|
||
private static final String API = "api"; | ||
|
||
private final RedisConnectionFactory redisConnectionFactory; | ||
|
||
@Value("${application.type:#{null}}") | ||
private String applicationType; | ||
|
||
@Bean | ||
public CacheManager wincubeAccessTokenCacheManager() { | ||
if (!API.equals(applicationType)) { | ||
return new NoCacheManager(); | ||
} | ||
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() | ||
.serializeKeysWith(SerializationPair.fromSerializer(new StringRedisSerializer())) | ||
.serializeValuesWith(SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) | ||
.entryTtl(Duration.ofHours(23)); // 캐시 저장 시간 23시간 설정, 윈큐브 토큰 지속시간이 24시간임 | ||
return RedisCacheManager.RedisCacheManagerBuilder | ||
.fromConnectionFactory(redisConnectionFactory) | ||
.cacheDefaults(redisCacheConfiguration) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/java/moa/global/config/cache/NoCacheManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package moa.global.config.cache; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import org.springframework.cache.Cache; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.concurrent.ConcurrentMapCache; | ||
|
||
public class NoCacheManager implements CacheManager { | ||
|
||
private final Cache noCache = new ConcurrentMapCache("nocache"); | ||
|
||
public Cache getCache(String name) { | ||
noCache.clear(); | ||
return noCache; | ||
} | ||
|
||
@Override | ||
public Collection<String> getCacheNames() { | ||
return Collections.emptyList(); | ||
} | ||
} |