Search in sources :

Example 11 with JCacheCacheManager

use of org.springframework.cache.jcache.JCacheCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method ehcache3AsJCacheWithCaches.

@Test
public void ehcache3AsJCacheWithCaches() {
    String cachingProviderFqn = EhcacheCachingProvider.class.getName();
    load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Example 12 with JCacheCacheManager

use of org.springframework.cache.jcache.JCacheCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method jCacheCacheWithExistingJCacheManager.

@Test
public void jCacheCacheWithExistingJCacheManager() {
    load(JCacheCustomCacheManager.class, "spring.cache.type=jcache");
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    assertThat(cacheManager.getCacheManager()).isEqualTo(this.context.getBean("customJCacheCacheManager"));
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Example 13 with JCacheCacheManager

use of org.springframework.cache.jcache.JCacheCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method infinispanAsJCacheWithConfig.

@Test
public void infinispanAsJCacheWithConfig() throws IOException {
    String cachingProviderFqn = JCachingProvider.class.getName();
    String configLocation = "infinispan.xml";
    load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation);
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    Resource configResource = new ClassPathResource(configLocation);
    assertThat(cacheManager.getCacheManager().getURI()).isEqualTo(configResource.getURI());
}
Also used : Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 14 with JCacheCacheManager

use of org.springframework.cache.jcache.JCacheCacheManager in project spring-boot by spring-projects.

the class JCacheCacheConfiguration method jCacheCacheManager.

@Bean
@ConditionalOnMissingBean
public CacheManager jCacheCacheManager() throws IOException {
    CacheManager jCacheCacheManager = createCacheManager();
    List<String> cacheNames = this.cacheProperties.getCacheNames();
    if (!CollectionUtils.isEmpty(cacheNames)) {
        for (String cacheName : cacheNames) {
            jCacheCacheManager.createCache(cacheName, getDefaultCacheConfiguration());
        }
    }
    customize(jCacheCacheManager);
    return jCacheCacheManager;
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) CacheManager(javax.cache.CacheManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

JCacheCacheManager (org.springframework.cache.jcache.JCacheCacheManager)14 Test (org.junit.Test)13 ClassPathResource (org.springframework.core.io.ClassPathResource)4 Resource (org.springframework.core.io.Resource)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastCacheManager (com.hazelcast.spring.cache.HazelcastCacheManager)1 CacheManager (javax.cache.CacheManager)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1