Skip to content

fix: 공통 추천 목록의 오래된 인메모리 캐시 제거#800

Merged
Hexeong merged 2 commits into
developfrom
fix/798-solve-old-recommend-caching-data
Jun 27, 2026
Merged

fix: 공통 추천 목록의 오래된 인메모리 캐시 제거#800
Hexeong merged 2 commits into
developfrom
fix/798-solve-old-recommend-caching-data

Conversation

@Hexeong

@Hexeong Hexeong commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

작업 내용

  • GeneralUnivApplyInfoRecommendService에서 서버 기동 시점에 공통 추천 목록을 저장하던 generalRecommends 인메모리 캐시를 제거했습니다.
  • 공통 추천 목록은 Redis 캐시만 사용하도록 변경했습니다.
    • Redis cache hit: 캐시된 추천 응답 반환
    • Redis cache miss: 현재 DB의 termId 기준으로 추천 목록 조회 후 Redis에 저장하고 반환
  • 공통 추천 Redis key에 termId를 포함했습니다.
    • university:recommend:general:{termId}
  • 공통 추천 TTL을 86400초에서 3600초로 낮췄습니다.
  • 개인 추천 부족분을 채울 때도 새 공통 추천 캐시 흐름을 사용하도록 수정했습니다.
  • Redis 캐시 삭제 후 서버 재시작 없이 DB 기준으로 추천 목록이 재생성되는 회귀 테스트를 추가했습니다.

특이 사항

이번 변경 방식을 선택한 이유는 캐시의 출처를 Redis 하나로 단순화하기 위해서입니다.

기존 방식은 서버 기동 시점에 생성한 generalRecommends 인메모리 객체와 Redis 캐시를 함께 사용했습니다. 이 구조에서는 잘못된 추천 응답이 Redis에 저장된 경우 DEL university:recommend:general로 Redis 값을 삭제해도, 서버 메모리에 남아 있는 오래된 generalRecommends가 같은 값을 다시 Redis에 저장했습니다. 그래서 잘못된 캐싱을 운영에서 해소하려면 결국 서버 재시작이 필요하다는 단점이 있었습니다.

이번 변경으로 Redis 캐시가 비워졌을 때 현재 DB 기준으로 추천 목록이 다시 만들어지므로, 데이터 정합성 문제가 생겼을 때 서버 재시작 없이 캐시 삭제만으로 복구할 수 있습니다.

기존 어드민 캐시 무효화는 university:recommend:general prefix 기반이라, 새 key인 university:recommend:general:{termId}도 함께 무효화됩니다.

테스트:

bash ./gradlew test --tests GeneralUnivApplyInfoRecommendServiceTest --tests UnivApplyInfoRecommendServiceTest

리뷰 요구사항 (선택)

  • 공통 추천 TTL을 3600초로 낮춘 것이 적절한지 확인 부탁드립니다.
    • ORDER BY RAND() 비용을 고려하면 너무 짧은 TTL은 부담이 될 수 있습니다.
    • 반대로 기존 86400초는 잘못된 추천 데이터가 오래 유지될 수 있어 운영 복구 관점에서 길다고 판단했습니다.
    • 현재는 추천 목록이 완전 실시간일 필요는 없지만, 데이터 import/update 이후 stale cache가 하루 유지되는 것은 피하고자 1시간으로 조정했습니다.
  • termId를 캐시 key에 포함한 방식이 현재 term 변경 시나리오에 충분한지도 함께 봐주시면 좋겠습니다.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Hexeong, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 5 minutes and 5 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2efcda54-0bb8-4c22-9988-c0af03565d8c

📥 Commits

Reviewing files that changed from the base of the PR and between 4f763ed and 30c579b.

📒 Files selected for processing (2)
  • src/main/java/com/example/solidconnection/university/service/GeneralUnivApplyInfoRecommendService.java
  • src/test/java/com/example/solidconnection/university/service/GeneralUnivApplyInfoRecommendServiceTest.java

Walkthrough

  1. 일반 추천 서비스가 초기화 저장 방식에서 요청 시 조회 방식으로 바뀌고, termIdtermName을 받아 응답 DTO를 반환합니다.
  2. 개인 추천 서비스가 미리보기 응답 기준으로 정리되고, 일반 추천을 선택된 항목 제외 후 보강하는 흐름으로 바뀝니다.
  3. 관련 테스트가 새 호출 시그니처와 캐시 무효화 동작에 맞게 수정되었습니다.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • wibaek
  • lsy1307
  • Gyuhyeok99
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 공통 추천의 오래된 인메모리 캐시 제거라는 핵심 변경을 직접적으로 잘 요약합니다.
Description check ✅ Passed 관련 이슈, 작업 내용, 특이 사항, 리뷰 요구사항이 모두 포함되어 템플릿을 충분히 따릅니다.
Linked Issues check ✅ Passed 인메모리 캐시 제거, termId 기반 재조회, Redis 삭제 후 DB 재생성, 회귀 테스트 추가가 요구사항과 일치합니다.
Out of Scope Changes check ✅ Passed TTL 조정과 테스트 추가는 캐시 재생성 문제 해결에 부수적으로 연결된 범위 내 변경입니다.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/798-solve-old-recommend-caching-data

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Hexeong Hexeong changed the title [Bug] 공통 추천 목록의 오래된 인메모리 캐시 제거 fix: 공통 추천 목록의 오래된 인메모리 캐시 제거 Jun 26, 2026
@Hexeong Hexeong self-assigned this Jun 26, 2026
@Hexeong Hexeong added the 버그 Something isn't working label Jun 26, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f763ed65b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ThunderingHerdCaching(
key = "university:recommend:general:{0}",
cacheManager = "customCacheManager",
ttlSec = GENERAL_RECOMMEND_CACHE_TTL_SEC

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute cached recommendations instead of extending stale values

For this @ThunderingHerdCaching cache, ttlSec does not bound staleness under traffic: ThunderingHerdCachingAspect.refreshCache handles the last-10%-of-TTL path by calling getAndExpire and returning cachedValue, not by proceeding to rebuild from DB. When a popular /univ-apply-infos/recommend key 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 👍 / 👎.

@Hexeong Hexeong Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분은 별도로 #801 에서 작업할 예정입니다 :)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/example/solidconnection/university/service/GeneralUnivApplyInfoRecommendService.java`:
- Around line 30-39: 현재 getGeneralRecommends의 캐시 키가 termId만 사용해서 termName 변경 시
이전 응답이 TTL 동안 남을 수 있으니, GeneralUnivApplyInfoRecommendService의 캐시 계약을 더 안전하게
고정하세요. Term 갱신/삭제 경로에서 university:recommend:general:{termId}를 evict하도록 추가하거나,
필요하면 캐시 키에 termName 또는 Term 버전을 포함하도록 수정해 응답과 입력 계약이 항상 일치하게 만드세요.

In
`@src/test/java/com/example/solidconnection/university/service/GeneralUnivApplyInfoRecommendServiceTest.java`:
- Around line 44-56: The test setup in GeneralUnivApplyInfoRecommendServiceTest
should clear the general recommendation cache before each test so results stay
isolated. Update setUp() to remove the Redis entry for
university:recommend:general:{termId} after creating the term and before
building currentTermUnivApplyInfos, using the existing cache/redis access used
by the recommendation service or test fixtures. This ensures prior test
responses cannot leak into tests that reuse the same termId.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7887c5f7-eefc-4c0b-84cf-0046bf0ffcf1

📥 Commits

Reviewing files that changed from the base of the PR and between a071e6b and 4f763ed.

📒 Files selected for processing (4)
  • src/main/java/com/example/solidconnection/university/service/GeneralUnivApplyInfoRecommendService.java
  • src/main/java/com/example/solidconnection/university/service/UnivApplyInfoRecommendService.java
  • src/test/java/com/example/solidconnection/university/service/GeneralUnivApplyInfoRecommendServiceTest.java
  • src/test/java/com/example/solidconnection/university/service/UnivApplyInfoRecommendServiceTest.java

@lsy1307 lsy1307 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다. codex가 지적한 부분만 수정하면 될 것 같은데 다른 pr에서 수정하신다고 하셨으니 이대로 마무리하시면 될 것 같습니다.

@Hexeong Hexeong merged commit ca490f1 into develop Jun 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

버그 Something isn't working 최종 리뷰 최소 1명 필수

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: 추천 API가 오래된 공통 추천 목록을 재캐싱하는 문제

2 participants