Skip to content

Commit

Permalink
Feat: 외부 weather api 캐싱 어노테이션을 WeatherClientProxy.getWeatherInfo 메서드에…
Browse files Browse the repository at this point in the history
… 추가 (#215)
  • Loading branch information
Jaewon-pro authored Sep 20, 2024
1 parent 5222765 commit 4fd6f5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/dnd/runus/global/constant/CacheType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Getter
public enum CacheType {
WEATHER(Name.WEATHER, Duration.ofMinutes(10), 100),
;
private final String cacheName;
private final Duration expireAfterWrite;
Expand All @@ -16,4 +17,8 @@ public enum CacheType {
this.expireAfterWrite = expireAfterWrite;
this.maximumSize = maximumSize;
}

public static class Name {
public static final String WEATHER = "weather";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import static com.dnd.runus.global.constant.CacheType.Name.WEATHER;

@Slf4j
@Primary
@Component
Expand All @@ -25,6 +28,7 @@ public WeatherClientProxy(
}

@Override
@Cacheable(cacheNames = WEATHER, key = "#longitude + ':' + #latitude")
@CircuitBreaker(name = "weatherClient", fallbackMethod = "fallback")
public WeatherInfo getWeatherInfo(double longitude, double latitude) {
return mainWeatherClient.getWeatherInfo(longitude, latitude);
Expand Down

0 comments on commit 4fd6f5d

Please sign in to comment.