Search in sources :

Example 1 with CouchbaseCacheManager

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);
}
Also used : Couchbase(org.springframework.boot.autoconfigure.cache.CacheProperties.Couchbase) CouchbaseCacheManager(org.springframework.data.couchbase.cache.CouchbaseCacheManager) CouchbaseCacheManagerBuilder(org.springframework.data.couchbase.cache.CouchbaseCacheManager.CouchbaseCacheManagerBuilder) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with CouchbaseCacheManager

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();
    });
}
Also used : CouchbaseCacheManager(org.springframework.data.couchbase.cache.CouchbaseCacheManager) Test(org.junit.jupiter.api.Test)

Example 3 with CouchbaseCacheManager

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));
    });
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RedisCacheConfiguration(org.springframework.data.redis.cache.RedisCacheConfiguration) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) BDDMockito.given(org.mockito.BDDMockito.given) MutableConfiguration(javax.cache.configuration.MutableConfiguration) MockCacheManager(org.springframework.boot.autoconfigure.cache.support.MockCachingProvider.MockCacheManager) Resource(org.springframework.core.io.Resource) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) Test(org.junit.jupiter.api.Test) BeanPostProcessor(org.springframework.beans.factory.config.BeanPostProcessor) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) CachingConfigurer(org.springframework.cache.annotation.CachingConfigurer) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Hazelcast(com.hazelcast.core.Hazelcast) NoOpCacheManager(org.springframework.cache.support.NoOpCacheManager) Mockito.mock(org.mockito.Mockito.mock) CouchbaseCacheManager(org.springframework.data.couchbase.cache.CouchbaseCacheManager) Cache(org.springframework.cache.Cache) CouchbaseClientFactory(org.springframework.data.couchbase.CouchbaseClientFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheResolver(org.springframework.cache.interceptor.CacheResolver) ArrayList(java.util.ArrayList) HazelcastCacheManager(com.hazelcast.spring.cache.HazelcastCacheManager) BeanCreationException(org.springframework.beans.factory.BeanCreationException) CacheManager(org.springframework.cache.CacheManager) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) Duration(javax.cache.expiry.Duration) EnableCaching(org.springframework.cache.annotation.EnableCaching) CouchbaseCache(org.springframework.data.couchbase.cache.CouchbaseCache) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) Caching(javax.cache.Caching) Import(org.springframework.context.annotation.Import) RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) CaffeineSpec(com.github.benmanes.caffeine.cache.CaffeineSpec) HazelcastAutoConfiguration(org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration) JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) MockCachingProvider(org.springframework.boot.autoconfigure.cache.support.MockCachingProvider) AssertableApplicationContext(org.springframework.boot.test.context.assertj.AssertableApplicationContext) Bean(org.springframework.context.annotation.Bean) CouchbaseCacheConfiguration(org.springframework.data.couchbase.cache.CouchbaseCacheConfiguration) Collections(java.util.Collections) ClassPathExclusions(org.springframework.boot.testsupport.classpath.ClassPathExclusions) CouchbaseCacheConfiguration(org.springframework.data.couchbase.cache.CouchbaseCacheConfiguration) CouchbaseCacheManager(org.springframework.data.couchbase.cache.CouchbaseCacheManager) Test(org.junit.jupiter.api.Test)

Example 4 with CouchbaseCacheManager

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);
    });
}
Also used : CouchbaseCacheManager(org.springframework.data.couchbase.cache.CouchbaseCacheManager) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) CouchbaseCache(org.springframework.data.couchbase.cache.CouchbaseCache) Test(org.junit.jupiter.api.Test)

Example 5 with CouchbaseCacheManager

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);
    });
}
Also used : CouchbaseCacheManager(org.springframework.data.couchbase.cache.CouchbaseCacheManager) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) CouchbaseCache(org.springframework.data.couchbase.cache.CouchbaseCache) Test(org.junit.jupiter.api.Test)

Aggregations

CouchbaseCacheManager (org.springframework.data.couchbase.cache.CouchbaseCacheManager)5 Test (org.junit.jupiter.api.Test)4 Cache (org.springframework.cache.Cache)3 CaffeineCache (org.springframework.cache.caffeine.CaffeineCache)3 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)3 Bean (org.springframework.context.annotation.Bean)2 CouchbaseCache (org.springframework.data.couchbase.cache.CouchbaseCache)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 CaffeineSpec (com.github.benmanes.caffeine.cache.CaffeineSpec)1 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 Hazelcast (com.hazelcast.core.Hazelcast)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastCacheManager (com.hazelcast.spring.cache.HazelcastCacheManager)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Caching (javax.cache.Caching)1 CompleteConfiguration (javax.cache.configuration.CompleteConfiguration)1 MutableConfiguration (javax.cache.configuration.MutableConfiguration)1 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)1