-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedisClusterCacheManagerBuilder.java
33 lines (27 loc) · 1.36 KB
/
RedisClusterCacheManagerBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import data.cache.CacheSpecs;
import data.cache.RedisClusterCacheConfiguration;
import org.springframework.cache.CacheManager;
import org.springframework.data.redis.cache.RedisCacheManager;
import java.util.Map;
public class RedisClusterCacheManagerBuilder implements CacheManagerBuilder<RedisClusterCacheConfiguration> {
@Override
public CacheManager build(Map<String, CacheSpecs> specs,
RedisClusterCacheConfiguration redisClusterCacheConfiguration) {
RedisCacheManager manager = RedisCacheManager.builder(redisClusterCacheConfiguration.redisCacheWriter())
.cacheDefaults(redisClusterCacheConfiguration.defaultRedisCacheConfiguration())
.withInitialCacheConfigurations(geCacheConfigurations(specs, redisClusterCacheConfiguration))
.build();
manager.initializeCaches();
return manager;
}
private Map<String, RedisCacheConfiguration> geCacheConfigurations(Map<String, CacheSpecs> specs,
RedisClusterCacheConfiguration redisClusterCacheConfiguration) {
Map<String, RedisCacheConfiguration> cacheConfigurations = new HashMap<>();
RedisCacheConfiguration defaultCacheConfiguration = redisClusterCacheConfiguration.defaultRedisCacheConfiguration();
specs.entrySet().forEach(entry -> {
cacheConfigurations
.put(entry.getKey(), defaultCacheConfiguration.entryTtl(Duration.ofSeconds(entry.getValue().getTtl())));
});
return cacheConfigurations;
}
}