Search in sources :

Example 1 with CaffeineCacheManager

use of org.springframework.cache.caffeine.CaffeineCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method validateCaffeineCacheWithStats.

private void validateCaffeineCacheWithStats() {
    CaffeineCacheManager cacheManager = validateCacheManager(CaffeineCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
    Cache foo = cacheManager.getCache("foo");
    foo.get("1");
    assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) CouchbaseCache(com.couchbase.client.spring.cache.CouchbaseCache)

Example 2 with CaffeineCacheManager

use of org.springframework.cache.caffeine.CaffeineCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method caffeineCacheWithExplicitCaches.

@Test
public void caffeineCacheWithExplicitCaches() {
    load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine", "spring.cache.cacheNames=foo");
    CaffeineCacheManager cacheManager = validateCacheManager(CaffeineCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("foo");
    Cache foo = cacheManager.getCache("foo");
    foo.get("1");
    // See next tests: no spec given so stats should be disabled
    assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(0L);
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) CouchbaseCache(com.couchbase.client.spring.cache.CouchbaseCache) Test(org.junit.Test)

Example 3 with CaffeineCacheManager

use of org.springframework.cache.caffeine.CaffeineCacheManager in project spring-boot by spring-projects.

the class CaffeineCacheConfiguration method cacheManager.

@Bean
public CaffeineCacheManager cacheManager() {
    CaffeineCacheManager cacheManager = createCacheManager();
    List<String> cacheNames = this.cacheProperties.getCacheNames();
    if (!CollectionUtils.isEmpty(cacheNames)) {
        cacheManager.setCacheNames(cacheNames);
    }
    return this.customizers.customize(cacheManager);
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with CaffeineCacheManager

use of org.springframework.cache.caffeine.CaffeineCacheManager in project spring-boot by spring-projects.

the class CaffeineCacheConfiguration method createCacheManager.

private CaffeineCacheManager createCacheManager() {
    CaffeineCacheManager cacheManager = new CaffeineCacheManager();
    setCacheBuilder(cacheManager);
    if (this.cacheLoader != null) {
        cacheManager.setCacheLoader(this.cacheLoader);
    }
    return cacheManager;
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager)

Aggregations

CaffeineCacheManager (org.springframework.cache.caffeine.CaffeineCacheManager)4 CouchbaseCache (com.couchbase.client.spring.cache.CouchbaseCache)2 Cache (org.springframework.cache.Cache)2 CaffeineCache (org.springframework.cache.caffeine.CaffeineCache)2 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)2 Test (org.junit.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1