Skip to content

fix: 지역 캐시 5분 revision 동기화 - #683

Merged
Whale0928 merged 4 commits into
mainfrom
fix/region-cache-refresh
Jul 29, 2026
Merged

fix: 지역 캐시 5분 revision 동기화#683
Whale0928 merged 4 commits into
mainfrom
fix/region-cache-refresh

Conversation

@bottlenote-app

Copy link
Copy Markdown
Contributor

개요

Product 지역 목록 Caffeine 캐시가 Admin 지역 변경 후 최대 24시간 오래된 값을 반환할 수 있던 문제를 보완합니다.

변경 내용

  • Product 시작 시 및 5분마다 지역 revision(count, max(lastModifyAt))을 조회합니다.
  • revision 변경 시 local_cache_alcohol_region_information를 비워 다음 Product 조회가 최신 DB 값을 다시 적재하도록 합니다.
  • 생성·수정·삭제를 감지할 수 있도록 revision에 건수와 최종 수정 시각을 함께 사용합니다.
  • Admin 지역 수정 시 JPA auditing의 lastModifyAt 갱신을 검증하는 통합 테스트를 추가했습니다.

검증

  • ./gradlew :bottlenote-product-api:test --tests app.bottlenote.alcohols.service.RegionCacheRefreshServiceTest
  • ./gradlew :bottlenote-product-api:unit_test

미검증/로컬 제약

  • Admin 통합 테스트의 lastModifyAt 검증은 로컬 Docker/Testcontainers 미가용으로 실행하지 못했습니다. 테스트 컴파일은 완료됐으며 CI 환경에서 확인이 필요합니다.

@bottlenote-noa bottlenote-noa Bot 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.

노아 코드 리뷰

판정: 수정 필요 (blocking 3건)

  • CI rule-tests가 2개 ArchUnit 규칙 위반으로 실패합니다.
  • 현재 revision (count, max(lastModifyAt))은 초 단위 timestamp 충돌 시 변경을 놓칠 수 있어, 해결하려는 24시간 stale-cache 문제가 남습니다.
  • 로컬에서 RegionCacheRefreshServiceTest 2건은 통과했고, Admin 통합 테스트도 CI에서 통과했습니다.

세부 내용은 inline comment를 확인해 주세요.


@Override
@Query(
"select new app.bottlenote.alcohols.dto.response.RegionCacheRevision(count(r), max(r.lastModifyAt)) from region r")

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.

🔴 Blocking — revision 충돌 가능

regions.last_modify_at은 현재 스키마에서 fractional precision 없는 timestamp라 초 단위입니다. 따라서 poll이 (N, 12:00:00)을 저장한 직후 같은 초에 다른 지역을 수정하면 (count, max(lastModifyAt))이 그대로여서 캐시를 비우지 못하고 최대 24시간 stale 상태가 남습니다.

지역 변경 트랜잭션마다 원자적으로 증가시키는 전용 revision 값을 두는 방식이 가장 안전합니다. 최소한 동일 timestamp/동일 count에서도 실제 변경을 잡는 회귀 테스트가 필요합니다.

refresh();
}

@Scheduled(cron = "${schedules.region.cache.refresh.cron:0 */5 * * * *}")

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.

🔴 Blocking — rule-tests 실패

@Service의 public 메서드는 @Transactional을 가져야 한다는 ArchUnit 규칙 때문에 initializeRevision()refresh()가 실패합니다. DB 조회 경계인 refresh()에는 @Transactional(readOnly = true)를 적용하고, initializeRevision()의 public 메서드 규칙도 프로젝트 방식에 맞게 충족시켜 주세요. 현재 CI rule-tests는 이 위반 2건으로 실패 중입니다.


import java.time.LocalDateTime;

public record RegionCacheRevision(long count, LocalDateTime lastModifyAt) {}

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.

🔴 Blocking — DTO 네이밍 규칙 위반

dto.response 최상위 타입은 이름이 Response로 끝나거나 Item을 포함해야 해서 ArchUnit이 실패합니다. 예: RegionCacheRevisionResponse로 변경하거나, 외부 응답 DTO가 아니라면 패키지/타입 역할을 재배치해 주세요.

@bottlenote-app
bottlenote-app Bot force-pushed the fix/region-cache-refresh branch from 49e645f to bf12b09 Compare July 29, 2026 06:24
@Whale0928
Whale0928 merged commit 5d60876 into main Jul 29, 2026
8 checks passed
@Whale0928
Whale0928 deleted the fix/region-cache-refresh branch July 29, 2026 06:52
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