diff --git a/cadio-core/build.gradle b/cadio-core/build.gradle index 7eab2415..8b50e815 100644 --- a/cadio-core/build.gradle +++ b/cadio-core/build.gradle @@ -1,7 +1,6 @@ dependencies { // Spring Boot implementation("org.springframework.boot:spring-boot-starter") - implementation("org.springframework.boot:spring-boot-starter-json") //TODO ClusterFactory 만들어지면 변경 api("com.datastax.oss:java-driver-core:${datastaxJavaDriverVersion}") @@ -11,12 +10,18 @@ dependencies { // implementation("com.datastax.oss:java-driver-query-builder:${datastaxJavaDriverVersion}") // implementation("com.datastax.oss:java-driver-mapper-runtime:${datastaxJavaDriverVersion}") - api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1") + // Json + implementation("org.springframework.boot:spring-boot-starter-json") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1") // CommonsLang3 api("org.apache.commons:commons-lang3:3.13.0") api("com.google.guava:guava:33.0.0-jre") api("org.apache.commons:commons-collections4:4.4") + + // Cache + implementation("org.springframework.boot:spring-boot-starter-cache") + implementation("com.github.ben-manes.caffeine:caffeine:3.1.8") } bootJar { diff --git a/cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/CacheType.java b/cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/CacheType.java new file mode 100644 index 00000000..50c22c95 --- /dev/null +++ b/cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/CacheType.java @@ -0,0 +1,36 @@ +package kr.hakdang.cadio.core.support.cache; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.Duration; + +/** + * CacheType + * + * @author seungh0 + * @since 2024-07-04 + */ +@Getter +public enum CacheType { + + CLUSTER(CacheTypeNames.CLUSTER, Duration.ofMinutes(1)), + ; + + private final String key; + private final Duration duration; + + CacheType(String key, Duration duration) { + this.key = key; + this.duration = duration; + } + + @NoArgsConstructor(access = AccessLevel.PRIVATE) + public static class CacheTypeNames { + + public static final String CLUSTER = "cluster"; + + } + +} diff --git a/cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/LocalCacheConfig.java b/cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/LocalCacheConfig.java new file mode 100644 index 00000000..d1e9092c --- /dev/null +++ b/cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/LocalCacheConfig.java @@ -0,0 +1,38 @@ +package kr.hakdang.cadio.core.support.cache; + +import com.github.benmanes.caffeine.cache.Caffeine; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.caffeine.CaffeineCache; +import org.springframework.cache.support.SimpleCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * LocalCacheConfig + * + * @author seungh0 + * @since 2024-07-04 + */ +@EnableCaching +@Configuration +public class LocalCacheConfig { + + @Bean + public CacheManager cacheManager() { + SimpleCacheManager cacheManager = new SimpleCacheManager(); + List caches = Arrays.stream(CacheType.values()) + .map(cache -> new CaffeineCache(cache.getKey(), Caffeine.newBuilder() + .expireAfterWrite(cache.getDuration()) + .build() + )) + .collect(Collectors.toList()); + cacheManager.setCaches(caches); + return cacheManager; + } + +}