Skip to content

월간 캘린더 프리패치 & 캐싱#85

Merged
kanghun1121 merged 8 commits intodevfrom
feat/monthly-prefetch
Mar 28, 2026
Merged

월간 캘린더 프리패치 & 캐싱#85
kanghun1121 merged 8 commits intodevfrom
feat/monthly-prefetch

Conversation

@kanghun1121
Copy link
Copy Markdown
Member

✏️ 변경 내용

  • 월간 ±1개월로 Prefetch 적용
  • 최대 12개월 캐싱 적용 (SWR)

✅ 체크리스트

  • 빌드 정상 동작
  • 불필요한 파일 없음

캐싱은 다음과 같이 SWR 기반으로 적용했습니다! (서버와 데이터 불일치 문제 때문)

image

- PhotoURLCache를 NSLock 제거 후 actor 기반 LRU 캐시(최대 12개)로 교체
- fetchPhotoURLs를 AsyncThrowingStream으로 변경하여 stale-while-revalidate 패턴 적용
  - 캐시 HIT 시 즉시 방출 후 서버 검증, 데이터 변경 시 재방출
  - 캐시 MISS 시 서버 응답만 방출
- FetchMonthlyCalendarDaysUseCase도 AsyncThrowingStream 반환으로 변경
- InvalidateMonthCacheUseCase 및 invalidatePhotoURLCache 제거 (LRU 자동 evict로 대체)
- PrefetchAdjacentMonthsUseCase 제거 및 FetchMonthlyCalendarDaysUseCase 내부로 통합
- MockFoodRecordRepository 시그니처 업데이트
@kanghun1121 kanghun1121 requested a review from enebin March 25, 2026 11:46
@kanghun1121 kanghun1121 self-assigned this Mar 25, 2026
public func execute(for period: DateInterval, currentMonth: Date) async throws -> [MonthlyCalendarDay] {
let calendar = Calendar.seoul
let recordsByDate = try await repository.fetchPhotoURLs(in: period.start...period.end)
public func execute(for period: DateInterval, currentMonth: Date) -> AsyncThrowingStream<[MonthlyCalendarDay], Error> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

데이터를 반응형으로 던져야하다보니 AsyncStream을 사용함!

Combine을 사용할까도 생각했는데, 그러면 Domain이 Combine을 의존해야 해서.. Concurrency로 했습니당

Copy link
Copy Markdown
Member

@enebin enebin left a comment

Choose a reason for hiding this comment

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

태스크 관리하는 거 코멘트 하나 있는데 그거 보고 수정하는거 맞는지 확인 한 번 해줘ㅎㅎ 나머지는 굿!

Comment thread FoodDiary/Domain/Sources/UseCase/FetchMonthlyCalendarDaysUseCase.swift Outdated
@kanghun1121 kanghun1121 requested a review from enebin March 28, 2026 11:32
@kanghun1121 kanghun1121 merged commit bc4bc34 into dev Mar 28, 2026
1 check failed
@kanghun1121 kanghun1121 deleted the feat/monthly-prefetch branch March 28, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants