Skip to content

Commit

Permalink
chore: 캐시 상세 설정
Browse files Browse the repository at this point in the history
- ttl 설정
- maxSize 설정
- cache 통계 위한 metric 활성화
  • Loading branch information
skylar1220 committed Nov 5, 2024
1 parent da1c00e commit dc3807c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions backend/src/main/java/reviewme/config/CacheManagerConfig.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}

0 comments on commit dc3807c

Please sign in to comment.