-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 캐쉬 적용 #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HwangTaeGyeong
wants to merge
1
commit into
develop
Choose a base branch
from
feature/hub/redis
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[feat] 캐쉬 적용 #123
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,8 +9,10 @@ | |
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 세터가 아니라 메서드로 만들어야 할까요?ㅜㅠ |
||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
|
|
||
66 changes: 66 additions & 0 deletions
66
...arta.cupeed.hub/src/main/java/com/sparta/cupeed/hub/infrastructure/redis/CacheConfig.java
This file contains hidden or 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,66 @@ | ||
| package com.sparta.cupeed.hub.infrastructure.redis; | ||
|
|
||
| // 나머지 import 문들 | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| import org.springframework.cache.annotation.EnableCaching; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.redis.cache.CacheKeyPrefix; | ||
| 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.RedisSerializationContext; | ||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.SerializationFeature; | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
|
|
||
| @Configuration | ||
| @EnableCaching | ||
| public class CacheConfig { | ||
|
|
||
| @Bean | ||
| // CacheManager로 진행해도 정상 동작 | ||
| public RedisCacheManager cacheManager( | ||
| RedisConnectionFactory redisConnectionFactory | ||
| ) { | ||
|
|
||
| ObjectMapper objectMapper = new ObjectMapper() | ||
| .registerModule(new JavaTimeModule()) | ||
| .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||
|
|
||
| objectMapper.activateDefaultTyping( | ||
| objectMapper.getPolymorphicTypeValidator(), | ||
| ObjectMapper.DefaultTyping.NON_FINAL | ||
| // JsonTypeInfo.As.PROPERTY | ||
| ); | ||
|
|
||
| GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(objectMapper); | ||
|
|
||
| // 설정 구성을 먼저 진행한다. | ||
| // Redis를 이용해서 Spring Cache를 사용할 때 | ||
| // Redis 관련 설정을 모아두는 클래스 | ||
| RedisCacheConfiguration configuration = RedisCacheConfiguration | ||
| .defaultCacheConfig() | ||
| // null을 캐싱 할것인지 | ||
| .disableCachingNullValues() | ||
| // 기본 캐시 유지 시간 (Time To Live) | ||
| .entryTtl(Duration.ofSeconds(120)) | ||
| // 캐시를 구분하는 접두사 설정 | ||
| .computePrefixWith(CacheKeyPrefix.simple()) | ||
| // 캐시에 저장할 값을 어떻게 직렬화 / 역직렬화 할것인지 | ||
| // .serializeValuesWith(SerializationPair.fromSerializer(RedisSerializer.json())) | ||
| .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) | ||
| .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(serializer)); | ||
| ; | ||
|
|
||
| return RedisCacheManager | ||
| .builder(redisConnectionFactory) | ||
| .cacheDefaults(configuration) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -25,6 +25,12 @@ spring: | |
| init: | ||
| mode: always | ||
|
|
||
| # 3. Redis 설정 | ||
| data: | ||
| redis: | ||
| host: localhost | ||
| port: 6379 | ||
|
|
||
| server: | ||
|
Comment on lines
+28
to
34
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 도커 컴포즈 파일 변경하시고 설정 파일도 맞춰서 수정해서 욜려주시면감사하게씁니당 ㅎㅅㅎ |
||
| port: 20040 | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cupeed 최상단에 적용해주세용 최상단에도 redis 설정 포트가 6379라 hub 관련된 redis 포트 변경해주세욥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
최상단꺼를 같이 사용하는건지 모르겠네여?ㅜㅠ