Replies: 1 comment
-
하루만에 잘 알아보고 정리해주셨군요 👍 블로깅 기대해도 될까요? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
지역 전체 조회 api 요청 시 3518 개의 행정구역에 대한 Area 데이터가 반환됩니다.
Area 데이터는 다음과 같은 특징을 갖습니다.
따라서 캐시를 적용하려고 합니다.
Local Cache vs Global Cache
Caching 은 Local Cache 와 Global Cache로 나뉩니다.
두 Cache 방법은 아래와 같은 특징을 갖습니다.
Local Cache
Global Cache
지역 조회 API 를 위해 infra를 새로 구축하는 것은 과도합니다. 따라서 Local Cache를 적용하고자 했습니다.
Local Cache 방법
Spring의 Cache Abstraction
Spring의 공식문서를 살펴보면, Spring은 개발자가 특정 기술에 종속되지 않고 캐시를 구현할 수 있도록 추상화된 인터페이스 등을 제공합니다.
implementation 'org.springframework.boot:spring-boot-starter-cache'
spring-boot-starter-cache
의존성을 추가해서 사용하면 됩니다!EhCache vs Caffeine
여러 캐시 라이브러리 중 EhCache 와 Caffeine를 살펴보았습니다.
EhCache 는 오랜 기간 많은 사람들에게 사용된 강자이고, Caffeine은 새롭게 떠오른 강자입니다.
이중 Caffeine을 선택했습니다.
이유는 다음과 같습니다.
Caffeine Cache 적용
Caffeine을 사용하기 위해 의존성을 추가합니다.
implementation 'com.github.ben-manes.caffeine:caffeine'
@configuration 을 통해 CaffeineCache를 포함한 CacheManager를 Bean 으로 등록합니다.
AreaService 에서 readAll 메서드를 실행 시 데이터를 캐시합니다.(
@Cacheable
)만약 새로운 Area 데이터가 생성될 경우 캐시를 삭제합니다.(
@CacheEvict
)적용 후
기존에 조회 요청 처리 시간은 100 ~ 120ms 걸렸습니다.
캐싱 이후 14 ~ 18ms 로 단축 되었습니다!
Beta Was this translation helpful? Give feedback.
All reactions