Search in sources :

Example 1 with SimpleCacheManager

use of org.springframework.cache.support.SimpleCacheManager in project spring-framework by spring-projects.

the class CacheTestUtils method createSimpleCacheManager.

/**
	 * Create a {@link SimpleCacheManager} with the specified cache(s).
	 * @param cacheNames the names of the caches to create
	 */
public static CacheManager createSimpleCacheManager(String... cacheNames) {
    SimpleCacheManager result = new SimpleCacheManager();
    List<Cache> caches = new ArrayList<>();
    for (String cacheName : cacheNames) {
        caches.add(new ConcurrentMapCache(cacheName));
    }
    result.setCaches(caches);
    result.afterPropertiesSet();
    return result;
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) ArrayList(java.util.ArrayList) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache)

Example 2 with SimpleCacheManager

use of org.springframework.cache.support.SimpleCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method genericCacheWithCaches.

@Test
public void genericCacheWithCaches() {
    load(GenericCacheConfiguration.class);
    SimpleCacheManager cacheManager = validateCacheManager(SimpleCacheManager.class);
    assertThat(cacheManager.getCache("first")).isEqualTo(this.context.getBean("firstCache"));
    assertThat(cacheManager.getCache("second")).isEqualTo(this.context.getBean("secondCache"));
    assertThat(cacheManager.getCacheNames()).hasSize(2);
}
Also used : SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Test(org.junit.Test)

Example 3 with SimpleCacheManager

use of org.springframework.cache.support.SimpleCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method genericCacheExplicitWithCaches.

@Test
public void genericCacheExplicitWithCaches() {
    load(GenericCacheConfiguration.class, "spring.cache.type=generic");
    SimpleCacheManager cacheManager = validateCacheManager(SimpleCacheManager.class);
    assertThat(cacheManager.getCache("first")).isEqualTo(this.context.getBean("firstCache"));
    assertThat(cacheManager.getCache("second")).isEqualTo(this.context.getBean("secondCache"));
    assertThat(cacheManager.getCacheNames()).hasSize(2);
}
Also used : SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Test(org.junit.Test)

Example 4 with SimpleCacheManager

use of org.springframework.cache.support.SimpleCacheManager in project spring-boot by spring-projects.

the class GenericCacheConfiguration method cacheManager.

@Bean
public SimpleCacheManager cacheManager(Collection<Cache> caches) {
    SimpleCacheManager cacheManager = new SimpleCacheManager();
    cacheManager.setCaches(caches);
    return this.customizers.customize(cacheManager);
}
Also used : SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with SimpleCacheManager

use of org.springframework.cache.support.SimpleCacheManager in project spring-framework by spring-projects.

the class AbstractJCacheTests method createSimpleCacheManager.

protected static CacheManager createSimpleCacheManager(String... cacheNames) {
    SimpleCacheManager result = new SimpleCacheManager();
    List<Cache> caches = new ArrayList<>();
    for (String cacheName : cacheNames) {
        caches.add(new ConcurrentMapCache(cacheName));
    }
    result.setCaches(caches);
    result.afterPropertiesSet();
    return result;
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) ArrayList(java.util.ArrayList) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Cache(org.springframework.cache.Cache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache)

Aggregations

SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)5 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)2 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Cache (org.springframework.cache.Cache)1 Bean (org.springframework.context.annotation.Bean)1