From d040c4f21976dffc4f69d8723de94033a7c92b5d Mon Sep 17 00:00:00 2001 From: "bottlenote-app[bot]" <289617182+bottlenote-app[bot]@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:57:19 +0900 Subject: [PATCH 1/3] fix: refresh region cache on revision change --- .../region/AdminRegionIntegrationTest.kt | 31 +++++++++ .../alcohols/domain/RegionRepository.java | 3 + .../dto/response/RegionCacheRevision.java | 5 ++ .../repository/JpaRegionQueryRepository.java | 6 ++ .../service/RegionCacheRefreshService.java | 42 ++++++++++++ .../RegionCacheRefreshServiceTest.java | 64 +++++++++++++++++++ .../fixture/InMemoryRegionRepository.java | 12 ++++ 7 files changed, 163 insertions(+) create mode 100644 bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java create mode 100644 bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java create mode 100644 bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java diff --git a/bottlenote-admin-api/src/test/kotlin/app/integration/region/AdminRegionIntegrationTest.kt b/bottlenote-admin-api/src/test/kotlin/app/integration/region/AdminRegionIntegrationTest.kt index fe5cb75d9..1cbd98a82 100644 --- a/bottlenote-admin-api/src/test/kotlin/app/integration/region/AdminRegionIntegrationTest.kt +++ b/bottlenote-admin-api/src/test/kotlin/app/integration/region/AdminRegionIntegrationTest.kt @@ -1,6 +1,7 @@ package app.integration.region import app.IntegrationTestSupport +import app.bottlenote.alcohols.domain.RegionRepository import app.bottlenote.alcohols.dto.request.AdminRegionCreateRequest import app.bottlenote.alcohols.dto.request.AdminRegionSortOrderRequest import app.bottlenote.alcohols.dto.request.AdminRegionUpdateRequest @@ -21,6 +22,9 @@ class AdminRegionIntegrationTest : IntegrationTestSupport() { @Autowired private lateinit var regionTestFactory: RegionTestFactory + @Autowired + private lateinit var regionRepository: RegionRepository + private lateinit var accessToken: String @BeforeEach @@ -133,6 +137,33 @@ class AdminRegionIntegrationTest : IntegrationTestSupport() { .bodyJson() .extractingPath("$.data.code").isEqualTo("REGION_UPDATED") } + + @Test + @DisplayName("지역 수정 시 lastModifyAt이 갱신된다") + fun updateRefreshesLastModifyAt() { + val region = regionTestFactory.persistRoot("스코트랜드", "ScotlandTypo", 10) + val before = regionRepository.findById(region.id!!).orElseThrow().lastModifyAt + Thread.sleep(1100) + + val request = AdminRegionUpdateRequest.builder() + .korName("스코틀랜드") + .engName("Scotland") + .description("정정") + .sortOrder(10) + .build() + + assertThat( + mockMvcTester + .put() + .uri("/v1/regions/${region.id}") + .header("Authorization", "Bearer $accessToken") + .contentType(MediaType.APPLICATION_JSON) + .content(mapper.writeValueAsString(request)) + ).hasStatusOk() + + val after = regionRepository.findById(region.id!!).orElseThrow().lastModifyAt + assertThat(after).isAfter(before) + } } @Nested diff --git a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java index f979f15dd..7e0d5476c 100644 --- a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java +++ b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java @@ -1,6 +1,7 @@ package app.bottlenote.alcohols.domain; import app.bottlenote.alcohols.dto.response.AdminRegionItem; +import app.bottlenote.alcohols.dto.response.RegionCacheRevision; import app.bottlenote.alcohols.dto.response.RegionsItem; import java.util.Collection; import java.util.List; @@ -14,6 +15,8 @@ public interface RegionRepository { List findAllRegionsResponse(); + RegionCacheRevision getCacheRevision(); + Page findAllRegions(String keyword, Pageable pageable); List findChildRegionIds(Long parentId); diff --git a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java new file mode 100644 index 000000000..0472fe6be --- /dev/null +++ b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java @@ -0,0 +1,5 @@ +package app.bottlenote.alcohols.dto.response; + +import java.time.LocalDateTime; + +public record RegionCacheRevision(long count, LocalDateTime lastModifyAt) {} diff --git a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java index ffd3e38e8..ad6f26fd8 100644 --- a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java +++ b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java @@ -3,6 +3,7 @@ import app.bottlenote.alcohols.domain.Region; import app.bottlenote.alcohols.domain.RegionRepository; import app.bottlenote.alcohols.dto.response.AdminRegionItem; +import app.bottlenote.alcohols.dto.response.RegionCacheRevision; import app.bottlenote.alcohols.dto.response.RegionsItem; import app.bottlenote.common.annotation.JpaRepositoryImpl; import java.util.Collection; @@ -24,6 +25,11 @@ public interface JpaRegionQueryRepository extends RegionRepository, CrudReposito """) List findAllRegionsResponse(); + @Override + @Query( + "select new app.bottlenote.alcohols.dto.response.RegionCacheRevision(count(r), max(r.lastModifyAt)) from region r") + RegionCacheRevision getCacheRevision(); + @Override @Query( """ diff --git a/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java b/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java new file mode 100644 index 000000000..11ee3e3a6 --- /dev/null +++ b/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java @@ -0,0 +1,42 @@ +package app.bottlenote.alcohols.service; + +import app.bottlenote.alcohols.domain.RegionRepository; +import app.bottlenote.alcohols.dto.response.RegionCacheRevision; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class RegionCacheRefreshService { + + private static final String REGION_CACHE_NAME = "local_cache_alcohol_region_information"; + + private final RegionRepository regionRepository; + private final CacheManager cacheManager; + private RegionCacheRevision lastKnownRevision; + + @EventListener(ApplicationReadyEvent.class) + public void initializeRevision() { + refresh(); + } + + @Scheduled(cron = "${schedules.region.cache.refresh.cron:0 */5 * * * *}") + public synchronized void refresh() { + RegionCacheRevision currentRevision = regionRepository.getCacheRevision(); + if (lastKnownRevision != null && !lastKnownRevision.equals(currentRevision)) { + Cache cache = cacheManager.getCache(REGION_CACHE_NAME); + if (cache != null) { + cache.clear(); + log.info("지역 캐시를 갱신했습니다. revision: {} -> {}", lastKnownRevision, currentRevision); + } + } + lastKnownRevision = currentRevision; + } +} diff --git a/bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java b/bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java new file mode 100644 index 000000000..1791844a6 --- /dev/null +++ b/bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java @@ -0,0 +1,64 @@ +package app.bottlenote.alcohols.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import app.bottlenote.alcohols.domain.Region; +import app.bottlenote.alcohols.fixture.InMemoryRegionRepository; +import java.time.LocalDateTime; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.concurrent.ConcurrentMapCacheManager; +import org.springframework.cache.interceptor.SimpleKey; +import org.springframework.test.util.ReflectionTestUtils; + +@Tag("unit") +@DisplayName("[unit] RegionCacheRefreshService") +class RegionCacheRefreshServiceTest { + + private static final String REGION_CACHE_NAME = "local_cache_alcohol_region_information"; + + private final InMemoryRegionRepository regionRepository = new InMemoryRegionRepository(); + private final CacheManager cacheManager = new ConcurrentMapCacheManager(REGION_CACHE_NAME); + private RegionCacheRefreshService service; + + @BeforeEach + void setUp() { + service = new RegionCacheRefreshService(regionRepository, cacheManager); + } + + @Test + @DisplayName("지역의 최종 수정 시각이 변경되면 Product 지역 캐시를 비운다") + void refresh_whenRegionLastModifyAtChanged_clearsRegionCache() { + Region region = Region.builder().korName("스코틀랜드").engName("Scotland").build(); + regionRepository.save(region); + service.refresh(); + + Cache cache = cacheManager.getCache(REGION_CACHE_NAME); + cache.put(SimpleKey.EMPTY, "cached-regions"); + ReflectionTestUtils.setField(region, "lastModifyAt", LocalDateTime.of(2026, 7, 29, 12, 5)); + + service.refresh(); + + assertThat(cache.get(SimpleKey.EMPTY)).isNull(); + } + + @Test + @DisplayName("지역이 삭제되면 Product 지역 캐시를 비운다") + void refresh_whenRegionDeleted_clearsRegionCache() { + Region region = Region.builder().korName("스코틀랜드").engName("Scotland").build(); + regionRepository.save(region); + service.refresh(); + + Cache cache = cacheManager.getCache(REGION_CACHE_NAME); + cache.put(SimpleKey.EMPTY, "cached-regions"); + regionRepository.delete(region); + + service.refresh(); + + assertThat(cache.get(SimpleKey.EMPTY)).isNull(); + } +} diff --git a/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java b/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java index d9364285e..fbdbb39e4 100644 --- a/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java +++ b/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java @@ -3,6 +3,7 @@ import app.bottlenote.alcohols.domain.Region; import app.bottlenote.alcohols.domain.RegionRepository; import app.bottlenote.alcohols.dto.response.AdminRegionItem; +import app.bottlenote.alcohols.dto.response.RegionCacheRevision; import app.bottlenote.alcohols.dto.response.RegionsItem; import java.util.ArrayList; import java.util.Collection; @@ -46,6 +47,17 @@ public List findAllRegionsResponse() { .toList(); } + @Override + public RegionCacheRevision getCacheRevision() { + return new RegionCacheRevision( + regions.size(), + regions.stream() + .map(Region::getLastModifyAt) + .filter(Objects::nonNull) + .max(Comparator.naturalOrder()) + .orElse(null)); + } + @Override public Page findAllRegions(String keyword, Pageable pageable) { List filtered = From bf12b09018085c622d9a51f6420ae8bb2d0c61d7 Mon Sep 17 00:00:00 2001 From: "bottlenote-app[bot]" <289617182+bottlenote-app[bot]@users.noreply.github.com> Date: Wed, 29 Jul 2026 15:23:51 +0900 Subject: [PATCH 2/3] fix: detect region cache content changes --- .../alcohols/domain/RegionRepository.java | 3 --- .../dto/response/RegionCacheRevision.java | 5 ----- .../alcohols/dto/response/RegionsItem.java | 2 ++ .../repository/JpaRegionQueryRepository.java | 6 ------ .../service/RegionCacheRefreshService.java | 17 ++++++++------- .../RegionCacheRefreshServiceTest.java | 21 ++++++++++++++++--- .../fixture/InMemoryRegionRepository.java | 11 ---------- 7 files changed, 29 insertions(+), 36 deletions(-) delete mode 100644 bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java diff --git a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java index 7e0d5476c..f979f15dd 100644 --- a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java +++ b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/domain/RegionRepository.java @@ -1,7 +1,6 @@ package app.bottlenote.alcohols.domain; import app.bottlenote.alcohols.dto.response.AdminRegionItem; -import app.bottlenote.alcohols.dto.response.RegionCacheRevision; import app.bottlenote.alcohols.dto.response.RegionsItem; import java.util.Collection; import java.util.List; @@ -15,8 +14,6 @@ public interface RegionRepository { List findAllRegionsResponse(); - RegionCacheRevision getCacheRevision(); - Page findAllRegions(String keyword, Pageable pageable); List findChildRegionIds(Long parentId); diff --git a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java deleted file mode 100644 index 0472fe6be..000000000 --- a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionCacheRevision.java +++ /dev/null @@ -1,5 +0,0 @@ -package app.bottlenote.alcohols.dto.response; - -import java.time.LocalDateTime; - -public record RegionCacheRevision(long count, LocalDateTime lastModifyAt) {} diff --git a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionsItem.java b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionsItem.java index aa1cd68e4..60a2075c3 100644 --- a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionsItem.java +++ b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/dto/response/RegionsItem.java @@ -1,9 +1,11 @@ package app.bottlenote.alcohols.dto.response; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; @Getter +@EqualsAndHashCode @AllArgsConstructor(staticName = "of") public class RegionsItem { private final Long regionId; diff --git a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java index ad6f26fd8..ffd3e38e8 100644 --- a/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java +++ b/bottlenote-mono/src/main/java/app/bottlenote/alcohols/repository/JpaRegionQueryRepository.java @@ -3,7 +3,6 @@ import app.bottlenote.alcohols.domain.Region; import app.bottlenote.alcohols.domain.RegionRepository; import app.bottlenote.alcohols.dto.response.AdminRegionItem; -import app.bottlenote.alcohols.dto.response.RegionCacheRevision; import app.bottlenote.alcohols.dto.response.RegionsItem; import app.bottlenote.common.annotation.JpaRepositoryImpl; import java.util.Collection; @@ -25,11 +24,6 @@ public interface JpaRegionQueryRepository extends RegionRepository, CrudReposito """) List findAllRegionsResponse(); - @Override - @Query( - "select new app.bottlenote.alcohols.dto.response.RegionCacheRevision(count(r), max(r.lastModifyAt)) from region r") - RegionCacheRevision getCacheRevision(); - @Override @Query( """ diff --git a/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java b/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java index 11ee3e3a6..5037f402a 100644 --- a/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java +++ b/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java @@ -1,7 +1,8 @@ package app.bottlenote.alcohols.service; import app.bottlenote.alcohols.domain.RegionRepository; -import app.bottlenote.alcohols.dto.response.RegionCacheRevision; +import app.bottlenote.alcohols.dto.response.RegionsItem; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationReadyEvent; @@ -9,10 +10,10 @@ import org.springframework.cache.CacheManager; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; @Slf4j -@Service +@Component @RequiredArgsConstructor public class RegionCacheRefreshService { @@ -20,7 +21,7 @@ public class RegionCacheRefreshService { private final RegionRepository regionRepository; private final CacheManager cacheManager; - private RegionCacheRevision lastKnownRevision; + private List lastKnownRegions; @EventListener(ApplicationReadyEvent.class) public void initializeRevision() { @@ -29,14 +30,14 @@ public void initializeRevision() { @Scheduled(cron = "${schedules.region.cache.refresh.cron:0 */5 * * * *}") public synchronized void refresh() { - RegionCacheRevision currentRevision = regionRepository.getCacheRevision(); - if (lastKnownRevision != null && !lastKnownRevision.equals(currentRevision)) { + List currentRegions = regionRepository.findAllRegionsResponse(); + if (lastKnownRegions != null && !lastKnownRegions.equals(currentRegions)) { Cache cache = cacheManager.getCache(REGION_CACHE_NAME); if (cache != null) { cache.clear(); - log.info("지역 캐시를 갱신했습니다. revision: {} -> {}", lastKnownRevision, currentRevision); + log.info("지역 캐시를 갱신했습니다."); } } - lastKnownRevision = currentRevision; + lastKnownRegions = currentRegions; } } diff --git a/bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java b/bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java index 1791844a6..a35f3565e 100644 --- a/bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java +++ b/bottlenote-product-api/src/test/java/app/bottlenote/alcohols/service/RegionCacheRefreshServiceTest.java @@ -31,15 +31,30 @@ void setUp() { } @Test - @DisplayName("지역의 최종 수정 시각이 변경되면 Product 지역 캐시를 비운다") - void refresh_whenRegionLastModifyAtChanged_clearsRegionCache() { + @DisplayName("지역이 추가되면 Product 지역 캐시를 비운다") + void refresh_whenRegionAdded_clearsRegionCache() { + service.refresh(); + + Cache cache = cacheManager.getCache(REGION_CACHE_NAME); + cache.put(SimpleKey.EMPTY, "cached-regions"); + regionRepository.save(Region.builder().korName("스코틀랜드").engName("Scotland").build()); + + service.refresh(); + + assertThat(cache.get(SimpleKey.EMPTY)).isNull(); + } + + @Test + @DisplayName("같은 최종 수정 시각에 지역 내용이 변경되면 Product 지역 캐시를 비운다") + void refresh_whenRegionContentChangedWithSameLastModifyAt_clearsRegionCache() { Region region = Region.builder().korName("스코틀랜드").engName("Scotland").build(); regionRepository.save(region); + ReflectionTestUtils.setField(region, "lastModifyAt", LocalDateTime.of(2026, 7, 29, 12, 5)); service.refresh(); Cache cache = cacheManager.getCache(REGION_CACHE_NAME); cache.put(SimpleKey.EMPTY, "cached-regions"); - ReflectionTestUtils.setField(region, "lastModifyAt", LocalDateTime.of(2026, 7, 29, 12, 5)); + region.update("스코틀랜드", "Scotland", null, "변경된 설명", null, null, null); service.refresh(); diff --git a/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java b/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java index fbdbb39e4..3b2bc34b0 100644 --- a/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java +++ b/bottlenote-test-support/src/main/java/app/bottlenote/alcohols/fixture/InMemoryRegionRepository.java @@ -3,7 +3,6 @@ import app.bottlenote.alcohols.domain.Region; import app.bottlenote.alcohols.domain.RegionRepository; import app.bottlenote.alcohols.dto.response.AdminRegionItem; -import app.bottlenote.alcohols.dto.response.RegionCacheRevision; import app.bottlenote.alcohols.dto.response.RegionsItem; import java.util.ArrayList; import java.util.Collection; @@ -47,16 +46,6 @@ public List findAllRegionsResponse() { .toList(); } - @Override - public RegionCacheRevision getCacheRevision() { - return new RegionCacheRevision( - regions.size(), - regions.stream() - .map(Region::getLastModifyAt) - .filter(Objects::nonNull) - .max(Comparator.naturalOrder()) - .orElse(null)); - } @Override public Page findAllRegions(String keyword, Pageable pageable) { From adde04ce3fe2483a01b9966361e4876a18d0aca1 Mon Sep 17 00:00:00 2001 From: "bottlenote-app[bot]" <289617182+bottlenote-app[bot]@users.noreply.github.com> Date: Wed, 29 Jul 2026 15:27:09 +0900 Subject: [PATCH 3/3] fix: add transactional region cache refresh --- bottlenote-product-api/build.gradle | 1 + .../alcohols/service/RegionCacheRefreshService.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bottlenote-product-api/build.gradle b/bottlenote-product-api/build.gradle index 20cf50081..c24aad70c 100644 --- a/bottlenote-product-api/build.gradle +++ b/bottlenote-product-api/build.gradle @@ -20,6 +20,7 @@ dependencies { // ===== Spring Boot Web ===== implementation libs.spring.boot.starter.web implementation libs.spring.boot.starter.validation + implementation libs.spring.boot.starter.data.jpa // OpenAPI 스펙 생성 (swagger-ui는 설정으로 비활성) implementation libs.springdoc.openapi.starter.webmvc.ui diff --git a/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java b/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java index 5037f402a..d1b4eabf9 100644 --- a/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java +++ b/bottlenote-product-api/src/main/java/app/bottlenote/alcohols/service/RegionCacheRefreshService.java @@ -10,10 +10,11 @@ import org.springframework.cache.CacheManager; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Slf4j -@Component +@Service @RequiredArgsConstructor public class RegionCacheRefreshService { @@ -24,11 +25,13 @@ public class RegionCacheRefreshService { private List lastKnownRegions; @EventListener(ApplicationReadyEvent.class) + @Transactional(readOnly = true) public void initializeRevision() { refresh(); } @Scheduled(cron = "${schedules.region.cache.refresh.cron:0 */5 * * * *}") + @Transactional(readOnly = true) public synchronized void refresh() { List currentRegions = regionRepository.findAllRegionsResponse(); if (lastKnownRegions != null && !lastKnownRegions.equals(currentRegions)) {