Skip to content

[DP-387] 트렌드 배치 완료 후 BE Redis 캐시 무효화 연동#59

Merged
suheon98 merged 4 commits intodevelopV2from
feature/DP-387-trend-cache-eviction
Apr 24, 2026
Merged

[DP-387] 트렌드 배치 완료 후 BE Redis 캐시 무효화 연동#59
suheon98 merged 4 commits intodevelopV2from
feature/DP-387-trend-cache-eviction

Conversation

@suheon98
Copy link
Copy Markdown
Collaborator

Summary

  • 트렌드 배치 완료 직후 BE DELETE /internal/trends/cache 를 호출해 Redis 캐시를 즉시 무효화
  • 기존에는 Redis TTL(6h) 만료 전까지 이전 데이터가 반환되는 문제가 있었음
  • CacheEvictionClient best-effort 설계 — 캐시 무효화 실패가 배치 전체 실패로 전파되지 않음

Changes

  • app/services/trend/cache_eviction.py (신규) — CacheEvictionClient: requests.delete 기반, 실패 시 warning 로그만
  • app/services/trend/orchestrator.pybackend_url + cache_evict_key 파라미터 추가, upsert() 직후 evict() 호출
  • scripts/run_trend_batch.py / run_trend_scheduler.pyBACKEND_URL + TREND_CACHE_EVICT_KEY 환경변수 읽어 오케스트레이터에 주입
  • .env.exampleTREND_CACHE_EVICT_KEY 항목 추가

환경변수 설정 필요

BACKEND_URL=https://...        # BE 서버 주소
TREND_CACHE_EVICT_KEY=...      # BE APP_TREND_CACHE_EVICT_KEY 와 동일 값

미설정 시 캐시 무효화 skip — 기존 동작(TTL 만료 후 갱신) 유지

Test plan

  • CacheEvictionClient 단위 테스트 8개 (성공/비204/네트워크 오류/타임아웃)
  • TrendOrchestrator 캐시 통합 테스트 5개 (클라이언트 생성 조건, upsert 후 evict 호출 검증)
  • 환경변수 설정 후 실제 배치 실행으로 캐시 무효화 동작 확인

🤖 Generated with Claude Code

suheon98 and others added 4 commits April 25, 2026 00:16
- CacheEvictionClient: DELETE /internal/trends/cache 호출, best-effort (실패 시 warning 로그만)
- TrendOrchestrator: backend_url + cache_evict_key 파라미터 추가, upsert 직후 evict() 호출
- run_trend_batch.py / run_trend_scheduler.py: BACKEND_URL + TREND_CACHE_EVICT_KEY 환경변수 주입
- .env.example: TREND_CACHE_EVICT_KEY 항목 추가
- 테스트: CacheEvictionClient 8개, 오케스트레이터 통합 5개

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…DP-387)

캐시 무효화 헤더(X-Internal-Key)가 기존 내부 API 인증 키와 동일하므로
별도 환경변수 불필요. cache_evict_key → internal_key 파라미터로 통일.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@suheon98 suheon98 merged commit dc6067a into developV2 Apr 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant