Search in sources :

Example 6 with ConcurrentMapCacheManager

use of org.springframework.cache.concurrent.ConcurrentMapCacheManager in project spring-boot by spring-projects.

the class SimpleCacheConfiguration method cacheManager.

@Bean
ConcurrentMapCacheManager cacheManager(CacheProperties cacheProperties, CacheManagerCustomizers cacheManagerCustomizers) {
    ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager();
    List<String> cacheNames = cacheProperties.getCacheNames();
    if (!cacheNames.isEmpty()) {
        cacheManager.setCacheNames(cacheNames);
    }
    return cacheManagerCustomizers.customize(cacheManager);
}
Also used : ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with ConcurrentMapCacheManager

use of org.springframework.cache.concurrent.ConcurrentMapCacheManager in project spring-boot by spring-projects.

the class CachesEndpointTests method namedCacheWithSeveralCacheManagers.

@Test
void namedCacheWithSeveralCacheManagers() {
    Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
    cacheManagers.put("test", new ConcurrentMapCacheManager("b", "dupe-cache"));
    cacheManagers.put("another", new ConcurrentMapCacheManager("c", "dupe-cache"));
    CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
    assertThatExceptionOfType(NonUniqueCacheException.class).isThrownBy(() -> endpoint.cache("dupe-cache", null)).withMessageContaining("dupe-cache").withMessageContaining("test").withMessageContaining("another");
}
Also used : ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) CacheManager(org.springframework.cache.CacheManager) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 8 with ConcurrentMapCacheManager

use of org.springframework.cache.concurrent.ConcurrentMapCacheManager in project spring-boot by spring-projects.

the class CachesEndpointTests method allCachesWithSingleCacheManager.

@Test
void allCachesWithSingleCacheManager() {
    CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", new ConcurrentMapCacheManager("a", "b")));
    Map<String, CacheManagerDescriptor> allDescriptors = endpoint.caches().getCacheManagers();
    assertThat(allDescriptors).containsOnlyKeys("test");
    CacheManagerDescriptor descriptors = allDescriptors.get("test");
    assertThat(descriptors.getCaches()).containsOnlyKeys("a", "b");
    assertThat(descriptors.getCaches().get("a").getTarget()).isEqualTo(ConcurrentHashMap.class.getName());
    assertThat(descriptors.getCaches().get("b").getTarget()).isEqualTo(ConcurrentHashMap.class.getName());
}
Also used : CacheManagerDescriptor(org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.jupiter.api.Test)

Example 9 with ConcurrentMapCacheManager

use of org.springframework.cache.concurrent.ConcurrentMapCacheManager in project spring-boot by spring-projects.

the class CachesEndpointTests method allCachesWithSeveralCacheManagers.

@Test
void allCachesWithSeveralCacheManagers() {
    Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
    cacheManagers.put("test", new ConcurrentMapCacheManager("a", "b"));
    cacheManagers.put("another", new ConcurrentMapCacheManager("a", "c"));
    CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
    Map<String, CacheManagerDescriptor> allDescriptors = endpoint.caches().getCacheManagers();
    assertThat(allDescriptors).containsOnlyKeys("test", "another");
    assertThat(allDescriptors.get("test").getCaches()).containsOnlyKeys("a", "b");
    assertThat(allDescriptors.get("another").getCaches()).containsOnlyKeys("a", "c");
}
Also used : CacheManagerDescriptor(org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) CacheManager(org.springframework.cache.CacheManager) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 10 with ConcurrentMapCacheManager

use of org.springframework.cache.concurrent.ConcurrentMapCacheManager in project spring-boot by spring-projects.

the class CachesEndpointTests method namedCacheWithUnknownCache.

@Test
void namedCacheWithUnknownCache() {
    CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", new ConcurrentMapCacheManager("b", "a")));
    CacheEntry entry = endpoint.cache("unknown", null);
    assertThat(entry).isNull();
}
Also used : ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) CacheEntry(org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentMapCacheManager (org.springframework.cache.concurrent.ConcurrentMapCacheManager)17 Test (org.junit.jupiter.api.Test)9 LinkedHashMap (java.util.LinkedHashMap)4 CacheEntry (org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry)4 CacheManager (org.springframework.cache.CacheManager)4 SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)4 Test (org.junit.Test)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 CacheManagerDescriptor (org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Bean (org.springframework.context.annotation.Bean)2 BeforeClass (org.junit.BeforeClass)1