use of org.springframework.data.couchbase.cache.CouchbaseCacheManager in project spring-boot by spring-projects.
the class CouchbaseCacheConfiguration method cacheManager.
@Bean
CouchbaseCacheManager cacheManager(CacheProperties cacheProperties, CacheManagerCustomizers customizers, ObjectProvider<CouchbaseCacheManagerBuilderCustomizer> couchbaseCacheManagerBuilderCustomizers, CouchbaseClientFactory clientFactory) {
List<String> cacheNames = cacheProperties.getCacheNames();
CouchbaseCacheManagerBuilder builder = CouchbaseCacheManager.builder(clientFactory);
Couchbase couchbase = cacheProperties.getCouchbase();
org.springframework.data.couchbase.cache.CouchbaseCacheConfiguration config = org.springframework.data.couchbase.cache.CouchbaseCacheConfiguration.defaultCacheConfig();
if (couchbase.getExpiration() != null) {
config = config.entryExpiry(couchbase.getExpiration());
}
builder.cacheDefaults(config);
if (!ObjectUtils.isEmpty(cacheNames)) {
builder.initialCacheNames(new LinkedHashSet<>(cacheNames));
}
couchbaseCacheManagerBuilderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
CouchbaseCacheManager cacheManager = builder.build();
return customizers.customize(cacheManager);
}
use of org.springframework.data.couchbase.cache.CouchbaseCacheManager in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method couchbaseCacheExplicit.
@Test
void couchbaseCacheExplicit() {
this.contextRunner.withUserConfiguration(CouchbaseConfiguration.class).withPropertyValues("spring.cache.type=couchbase").run((context) -> {
CouchbaseCacheManager cacheManager = getCacheManager(context, CouchbaseCacheManager.class);
assertThat(cacheManager.getCacheNames()).isEmpty();
});
}
use of org.springframework.data.couchbase.cache.CouchbaseCacheManager in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method couchbaseCacheWithCouchbaseCacheManagerBuilderCustomizer.
@Test
void couchbaseCacheWithCouchbaseCacheManagerBuilderCustomizer() {
this.contextRunner.withUserConfiguration(CouchbaseConfiguration.class).withPropertyValues("spring.cache.type=couchbase", "spring.cache.couchbase.expiration=15s").withBean(CouchbaseCacheManagerBuilderCustomizer.class, () -> (builder) -> builder.cacheDefaults(CouchbaseCacheConfiguration.defaultCacheConfig().entryExpiry(java.time.Duration.ofSeconds(10)))).run((context) -> {
CouchbaseCacheManager cacheManager = getCacheManager(context, CouchbaseCacheManager.class);
CouchbaseCacheConfiguration couchbaseCacheConfiguration = getDefaultCouchbaseCacheConfiguration(cacheManager);
assertThat(couchbaseCacheConfiguration.getExpiry()).isEqualTo(java.time.Duration.ofSeconds(10));
});
}
use of org.springframework.data.couchbase.cache.CouchbaseCacheManager in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method couchbaseCacheExplicitWithTtl.
@Test
void couchbaseCacheExplicitWithTtl() {
this.contextRunner.withUserConfiguration(CouchbaseConfiguration.class).withPropertyValues("spring.cache.type=couchbase", "spring.cache.cacheNames=foo,bar", "spring.cache.couchbase.expiration=2000").run((context) -> {
CouchbaseCacheManager cacheManager = getCacheManager(context, CouchbaseCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
Cache cache = cacheManager.getCache("foo");
assertThat(cache).isInstanceOf(CouchbaseCache.class);
assertThat(((CouchbaseCache) cache).getCacheConfiguration().getExpiry()).hasSeconds(2);
});
}
use of org.springframework.data.couchbase.cache.CouchbaseCacheManager in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method couchbaseCacheExplicitWithCaches.
@Test
void couchbaseCacheExplicitWithCaches() {
this.contextRunner.withUserConfiguration(CouchbaseConfiguration.class).withPropertyValues("spring.cache.type=couchbase", "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar").run((context) -> {
CouchbaseCacheManager cacheManager = getCacheManager(context, CouchbaseCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
Cache cache = cacheManager.getCache("foo");
assertThat(cache).isInstanceOf(CouchbaseCache.class);
assertThat(((CouchbaseCache) cache).getCacheConfiguration().getExpiry()).hasSeconds(0);
});
}
Aggregations