-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/CacheType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
|
||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
cadio-core/src/main/java/kr/hakdang/cadio/core/support/cache/LocalCacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CaffeineCache> 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; | ||
} | ||
|
||
} |