-
Notifications
You must be signed in to change notification settings - Fork 1
81 post redis #88
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
81 post redis #88
Conversation
- slice 반환 Post summary 캐시 - DB동기화 - update/delete시 Post객체&PostSummary객체 무효처리
LJW22222
left a comment
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.
고생많으셨습니다!
| public PostCacheDto getPost(Long postId) { | ||
| log.debug("캐시 미스 - DB에서 게시물 조회: postId={}", postId); | ||
| Post post = getPostQueryService.handle(postId); | ||
| return PostCacheDto.from(post); | ||
| } |
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.
해당 부분은 Post를 바로 반환하는게 맞는거 같습니다. DTO를 별도로 발행해서 반환해도 무방하지만, Post라는 Domain 자체가 VO객체이므로 Post를 반환후에, 별도로 데이터를 조합해서 내보내야 하는 경우에 Application계층이나 API계층에서 짜집기해서 내보내는 것이 맞는거 같습니다.
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.
해당 부분 수정했습니다!
| public Page<Post> getPostList(PostListRequest request) { | ||
| log.debug("캐시 미스 - DB에서 게시물 목록 조회: {}", request); | ||
| return getPostListQueryService.handle(request); | ||
| } |
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.
현재는 Page를 해서 캐시에 저장하고 있는데, 해당 부분은 제가 공용으로 쓸 수 있는 클래스 만들고 해당 클래스를 사용하도록 하면 될 것 같습니다.
| public PostSummaryResponse getPostSummary(Long postId) { | ||
| log.info("캐시 미스 - DB에서 게시물 요약 조회: postId={}", postId); | ||
|
|
||
| if (!getPostQueryService.existsById(postId)) { | ||
| log.info("게시물이 존재하지 않음: postId={}", postId); | ||
| return new PostSummaryResponse( | ||
| null, null, null, null, null, null, null | ||
| ); | ||
| } | ||
|
|
||
| PostSummaryResponse result = getPostQueryService.handlePostSummary(postId); | ||
| log.info("게시물 요약 조회 완료: postId={}", postId); | ||
|
|
||
| return result; | ||
| } |
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.
해당 부분 또한 동일합니다.
| @Bean("redisCacheManager") | ||
| public CacheManager redisCacheManager(RedisConnectionFactory connectionFactory) { | ||
| public RedisCacheManager redisCacheManager(RedisConnectionFactory connectionFactory) { | ||
| return RedisCacheManager.builder(connectionFactory) | ||
| .cacheDefaults(redisCacheConfiguration(Duration.ofMinutes(1))) | ||
| .withInitialCacheConfigurations(customConfigurationMap()) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean @Primary | ||
| public CacheManager cacheManager(RedisCacheManager redis, MeterRegistry registry) { | ||
| return new MeteredCacheManager(redis, registry); | ||
| public CacheManager cacheManager(@Qualifier("redisCacheManager") RedisCacheManager redisCacheManager, MeterRegistry registry) { | ||
| return new MeteredCacheManager(redisCacheManager, registry); | ||
| } |
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.
CacheManager로 해도 무방하지만, 정말 단순하게 궁금해서 그렇습니다. CacheManager -> RedisCacheManager로 바꾼 의도가 궁금합니다.
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.
이부분 노션 버그 리포트 정리해서 올렸습니다. 참고해주세요!
https://www.notion.so/leeporject/23e37ed0f4f880a9a179f7358efa0d81?source=copy_link
Post Redis 캐시 구현
개요
게시물 조회 성능 향상을 위한 Redis 캐시 시스템을 구현했습니다.
주요 변경사항
1. 캐시 설정 추가
POST_DETAIL,POST_LIST,POST_SLICE,POST_SUMMARY캐시 타입 정의2. 캐시 DTO 구현
PostCacheDto: Post 도메인 객체의 캐시 전용 DTO
@JsonTypeInfo어노테이션으로 타입 정보 보존from(),toPost()메서드로 변환 지원PostSliceCacheDto: Slice 객체의 캐시 전용 DTO
toSlice()메서드로 Spring Data Slice 복원3. 캐시 서비스 구현
기술적 특징
캐시 TTL 설정
직렬화 최적화
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)로 타입 안전성 보장Location,PostEmotionTag등) 직렬화 지원성능 개선 효과
테스트 고려사항