Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
fix: 공통 추천 목록의 오래된 인메모리 캐시 제거#800
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
31 changes: 18 additions & 13 deletions
31 .../com/example/solidconnection/university/service/GeneralUnivApplyInfoRecommendService.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
36 changes: 25 additions & 11 deletions
36 ...in/java/com/example/solidconnection/university/service/UnivApplyInfoRecommendService.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
89 changes: 72 additions & 17 deletions
89 .../example/solidconnection/university/service/GeneralUnivApplyInfoRecommendServiceTest.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 |
|---|---|---|
| @@ -4,11 +4,15 @@ | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertAll; | ||
| import com.example.solidconnection.cache.manager.CustomCacheManager; | ||
| import com.example.solidconnection.support.TestContainerSpringBootTest; | ||
| import com.example.solidconnection.term.domain.Term; | ||
| import com.example.solidconnection.term.fixture.TermFixture; | ||
| import com.example.solidconnection.university.domain.UnivApplyInfo; | ||
| import com.example.solidconnection.university.dto.UnivApplyInfoPreviewResponse; | ||
| import com.example.solidconnection.university.dto.UnivApplyInfoRecommendsResponse; | ||
| import com.example.solidconnection.university.fixture.UnivApplyInfoFixture; | ||
| import com.example.solidconnection.university.repository.UnivApplyInfoRepository; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| @@ -25,39 +29,90 @@ class GeneralUnivApplyInfoRecommendServiceTest { | ||
| @Autowired | ||
| private UnivApplyInfoFixture univApplyInfoFixture; | ||
| @Autowired | ||
| private UnivApplyInfoRepository univApplyInfoRepository; | ||
| @Autowired | ||
| private CustomCacheManager cacheManager; | ||
| @Autowired | ||
| private TermFixture termFixture; | ||
| private Term term; | ||
| private List<UnivApplyInfo> currentTermUnivApplyInfos; | ||
| @BeforeEach | ||
| void setUp() { | ||
| term = termFixture.현재_학기("2025-2"); | ||
| cacheManager.evictUsingPrefix("university:recommend:general:" + term.getId()); | ||
| univApplyInfoFixture.괌대학_A_지원_정보(term.getId()); | ||
| univApplyInfoFixture.버지니아공과대학_지원_정보(term.getId()); | ||
| univApplyInfoFixture.네바다주립대학_라스베이거스_지원_정보(term.getId()); | ||
| univApplyInfoFixture.메모리얼대학_세인트존스_A_지원_정보(term.getId()); | ||
| univApplyInfoFixture.서던덴마크대학교_지원_정보(term.getId()); | ||
| univApplyInfoFixture.코펜하겐IT대학_지원_정보(term.getId()); | ||
| univApplyInfoFixture.그라츠대학_지원_정보(term.getId()); | ||
| univApplyInfoFixture.그라츠공과대학_지원_정보(term.getId()); | ||
| univApplyInfoFixture.린츠_카톨릭대학_지원_정보(term.getId()); | ||
| univApplyInfoFixture.메이지대학_지원_정보(term.getId()); | ||
| generalUnivApplyInfoRecommendService.init(); | ||
| currentTermUnivApplyInfos = List.of( | ||
| univApplyInfoFixture.괌대학_A_지원_정보(term.getId()), | ||
| univApplyInfoFixture.버지니아공과대학_지원_정보(term.getId()), | ||
| univApplyInfoFixture.네바다주립대학_라스베이거스_지원_정보(term.getId()), | ||
| univApplyInfoFixture.메모리얼대학_세인트존스_A_지원_정보(term.getId()), | ||
| univApplyInfoFixture.서던덴마크대학교_지원_정보(term.getId()), | ||
| univApplyInfoFixture.코펜하겐IT대학_지원_정보(term.getId()) | ||
| ); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @Test | ||
| void 모집_시기의_대학_지원_정보_중에서_랜덤하게_N개를_추천_목록으로_구성한다() { | ||
| // when | ||
| UnivApplyInfoRecommendsResponse response = generalUnivApplyInfoRecommendService.getGeneralRecommends( | ||
| term.getId(), | ||
| term.getName() | ||
| ); | ||
| List<Long> currentTermUnivApplyInfoIds = currentTermUnivApplyInfos.stream() | ||
| .map(UnivApplyInfo::getId) | ||
| .toList(); | ||
| // then | ||
| assertAll( | ||
| () -> assertThat(response.recommendedUniversities()).hasSize(RECOMMEND_UNIV_APPLY_INFO_NUM), | ||
| () -> assertThat(response.recommendedUniversities()) | ||
| .extracting(UnivApplyInfoPreviewResponse::id) | ||
| .isSubsetOf(currentTermUnivApplyInfoIds) | ||
| ); | ||
| } | ||
| @Test | ||
| void 캐시를_삭제하면_서버_재기동_없이_DB_기준으로_추천_목록을_다시_구성한다() { | ||
| // given | ||
| List<UnivApplyInfo> universities = generalUnivApplyInfoRecommendService.getGeneralRecommends(); | ||
| UnivApplyInfo deletedUnivApplyInfo = currentTermUnivApplyInfos.get(0); | ||
| UnivApplyInfoRecommendsResponse cachedResponse = generalUnivApplyInfoRecommendService.getGeneralRecommends( | ||
| term.getId(), | ||
| term.getName() | ||
| ); | ||
| univApplyInfoRepository.delete(deletedUnivApplyInfo); | ||
| UnivApplyInfo addedUnivApplyInfo = univApplyInfoFixture.그라츠대학_지원_정보(term.getId()); | ||
| // when | ||
| UnivApplyInfoRecommendsResponse responseBeforeCacheEvict = generalUnivApplyInfoRecommendService.getGeneralRecommends( | ||
| term.getId(), | ||
| term.getName() | ||
| ); | ||
| cacheManager.evictUsingPrefix("university:recommend:general:" + term.getId()); | ||
| UnivApplyInfoRecommendsResponse responseAfterCacheEvict = generalUnivApplyInfoRecommendService.getGeneralRecommends( | ||
| term.getId(), | ||
| term.getName() | ||
| ); | ||
| // when & then | ||
| // then | ||
| assertAll( | ||
| () -> assertThat(universities) | ||
| .extracting("termId") | ||
| .allMatch(term.getId()::equals), | ||
| () -> assertThat(universities).hasSize(RECOMMEND_UNIV_APPLY_INFO_NUM) | ||
| () -> assertThat(cachedResponse.recommendedUniversities()) | ||
| .extracting(UnivApplyInfoPreviewResponse::id) | ||
| .contains(deletedUnivApplyInfo.getId()), | ||
| () -> assertThat(responseBeforeCacheEvict.recommendedUniversities()) | ||
| .extracting(UnivApplyInfoPreviewResponse::id) | ||
| .contains(deletedUnivApplyInfo.getId()) | ||
| .doesNotContain(addedUnivApplyInfo.getId()), | ||
| () -> assertThat(responseAfterCacheEvict.recommendedUniversities()) | ||
| .hasSize(RECOMMEND_UNIV_APPLY_INFO_NUM) | ||
| .extracting(UnivApplyInfoPreviewResponse::id) | ||
| .contains(addedUnivApplyInfo.getId()) | ||
| .doesNotContain(deletedUnivApplyInfo.getId()) | ||
| ); | ||
| } | ||
| } | ||
11 changes: 4 additions & 7 deletions
11 ...ava/com/example/solidconnection/university/service/UnivApplyInfoRecommendServiceTest.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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
For this
@ThunderingHerdCachingcache,ttlSecdoes not bound staleness under traffic:ThunderingHerdCachingAspect.refreshCachehandles the last-10%-of-TTL path by callinggetAndExpireand returningcachedValue, not by proceeding to rebuild from DB. When a popular/univ-apply-infos/recommendkey is hit near expiry, a deleted or updated university can keep being served indefinitely unless an explicit prefix eviction runs, so the new 1-hour TTL does not provide the intended freshness window.Useful? React with 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.
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.
해당 부분은 별도로 #801 에서 작업할 예정입니다 :)