Skip to content

Commit

Permalink
Merge pull request #197 from softeerbootcamp4th/feature/#194-local-cache
Browse files Browse the repository at this point in the history
fix: 테스트 API 호출 시 로컬 캐시 갱신하도록수정
  • Loading branch information
k000927 authored Aug 21, 2024
2 parents 0635d16 + f0bf66f commit e13fa11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import JGS.CasperEvent.global.error.exception.CustomException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

Expand All @@ -19,6 +21,7 @@
public class RushEventCacheService {

private final RushEventRepository rushEventRepository;
private final CacheManager cacheManager;

@Cacheable(value = "todayEventCache", key = "#today")
public RushEventResponseDto getTodayEvent(LocalDate today) {
Expand All @@ -36,4 +39,11 @@ public RushEventResponseDto getTodayEvent(LocalDate today) {

return RushEventResponseDto.of(rushEventList.get(0));
}

public void setCacheValue(LocalDate today, RushEventResponseDto rushEvent) {
Cache cache = cacheManager.getCache("todayEventCache");
if (cache != null) {
cache.put(today, rushEvent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ public void setRushEvents() {

rushEvents.add(rushEvent);
}

rushEventCacheService.setCacheValue(LocalDate.now(), RushEventResponseDto.of(rushEvents.get(2)));
}


Expand Down

0 comments on commit e13fa11

Please sign in to comment.