From dc3807c151870e2df6359ae7e8922cd97ebeaeea Mon Sep 17 00:00:00 2001 From: hyeonjilee Date: Tue, 5 Nov 2024 09:18:09 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EC=BA=90=EC=8B=9C=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ttl 설정 - maxSize 설정 - cache 통계 위한 metric 활성화 --- .../reviewme/config/CacheManagerConfig.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/reviewme/config/CacheManagerConfig.java b/backend/src/main/java/reviewme/config/CacheManagerConfig.java index 5417a1930..3353cad1f 100644 --- a/backend/src/main/java/reviewme/config/CacheManagerConfig.java +++ b/backend/src/main/java/reviewme/config/CacheManagerConfig.java @@ -1,8 +1,10 @@ package reviewme.config; +import com.github.benmanes.caffeine.cache.Caffeine; +import java.time.Duration; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.cache.concurrent.ConcurrentMapCacheManager; +import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -13,7 +15,17 @@ public class CacheManagerConfig { @Bean - public CacheManager cacheManager() { - return new ConcurrentMapCacheManager(); + public CacheManager cacheManager(Caffeine caffeine) { + CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); + caffeineCacheManager.setCaffeine(caffeine); + return caffeineCacheManager; + } + + @Bean + public Caffeine caffeineConfig() { + return Caffeine.newBuilder() + .expireAfterAccess(Duration.ofDays(30)) + .maximumSize(1000) + .recordStats(); } }