Skip to content

Commit 6ed97e5

Browse files
committed
feat(be) : tour 캐시 스케줄러 개선
# Conflicts: # src/main/kotlin/com/back/koreaTravelGuide/KoreaTravelGuideApplication.kt
1 parent 4b264ef commit 6ed97e5

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

src/main/kotlin/com/back/koreaTravelGuide/KoreaTravelGuideApplication.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
55
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
66
import org.springframework.boot.runApplication
77
import org.springframework.cache.annotation.EnableCaching
8+
import org.springframework.scheduling.annotation.EnableScheduling
89
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
910

1011
@EnableCaching
12+
@EnableScheduling
13+
@SpringBootApplication(scanBasePackages = ["com.back.koreaTravelGuide"])
1114
@EnableJpaRepositories(basePackages = ["com.back.koreaTravelGuide.domain"])
1215
@SpringBootApplication(
1316
scanBasePackages = ["com.back.koreaTravelGuide"],
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
package com.back.koreaTravelGuide.domain.ai.tour.cache
22

3-
// TODO: 관광 정보 캐시 설정 - 캐시 주기 및 정책 관리 (필요시 구현)
4-
class TourCacheConfig
3+
import com.back.koreaTravelGuide.common.logging.log
4+
import org.springframework.cache.annotation.CacheEvict
5+
import org.springframework.context.annotation.Configuration
6+
import org.springframework.scheduling.annotation.Scheduled
7+
8+
@Configuration
9+
class TourCacheConfig {
10+
companion object {
11+
private val TOUR_CACHE_NAMES = arrayOf("tourAreaBased", "tourLocationBased", "tourDetail")
12+
}
13+
14+
// 매일 자정(00:00)마다 모든 캐시 항목을 무효화
15+
@CacheEvict(cacheNames = ["tourAreaBased", "tourLocationBased", "tourDetail"], allEntries = true)
16+
@Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Seoul")
17+
fun clearTourCaches() {
18+
log.info("clearTourCaches - evicting {}", TOUR_CACHE_NAMES.joinToString())
19+
}
20+
}

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/tour/service/core/TourAreaBasedServiceCore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TourAreaBasedServiceCore(
1515
@Cacheable(
1616
"tourAreaBased",
1717
key = "#tourParams.contentTypeId + '_' + #tourParams.areaCode + '_' + #tourParams.sigunguCode",
18+
unless = "#result == null",
1819
)
1920
override fun fetchAreaBasedTours(tourParams: TourParams): TourResponse {
2021
if (

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/tour/service/core/TourDetailServiceCore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service
1212
class TourDetailServiceCore(
1313
private val tourApiClient: TourApiClient,
1414
) : TourDetailUseCase {
15-
@Cacheable("tourDetail", key = "#detailParams.contentId")
15+
@Cacheable("tourDetail", key = "#detailParams.contentId", unless = "#result == null")
1616
override fun fetchTourDetail(detailParams: TourDetailParams): TourDetailResponse {
1717
if (detailParams.contentId == "127974") {
1818
return PRESET_DETAIL_RESPONSE

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/tour/service/core/TourLocationBasedServiceCore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class TourLocationBasedServiceCore(
1818
key =
1919
"#tourParams.contentTypeId + '_' + #tourParams.areaCode + '_' + #tourParams.sigunguCode + " +
2020
"'_' + #locationParams.mapX + '_' + #locationParams.mapY + '_' + #locationParams.radius",
21+
unless = "#result == null",
2122
)
2223
override fun fetchLocationBasedTours(
2324
tourParams: TourParams,

0 commit comments

Comments
 (0)