Search in sources :

Example 26 with CacheManager

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

the class CachesEndpointTests method namedCacheWithSeveralCacheManagersWithCacheManagerFilter.

@Test
void namedCacheWithSeveralCacheManagersWithCacheManagerFilter() {
    Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
    cacheManagers.put("test", new ConcurrentMapCacheManager("b", "a"));
    cacheManagers.put("another", new ConcurrentMapCacheManager("c", "a"));
    CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
    CacheEntry entry = endpoint.cache("a", "test");
    assertThat(entry).isNotNull();
    assertThat(entry.getCacheManager()).isEqualTo("test");
    assertThat(entry.getName()).isEqualTo("a");
}
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) CacheEntry(org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 27 with CacheManager

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

the class CachesEndpointTests method clearCacheWithSeveralCacheManagersWithCacheManagerFilter.

@Test
void clearCacheWithSeveralCacheManagersWithCacheManagerFilter() {
    Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
    Cache a = mockCache("a");
    Cache b = mockCache("b");
    cacheManagers.put("test", cacheManager(a, b));
    Cache anotherA = mockCache("a");
    cacheManagers.put("another", cacheManager(anotherA));
    CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
    assertThat(endpoint.clearCache("a", "another")).isTrue();
    then(a).should(never()).clear();
    then(anotherA).should().clear();
    then(b).should(never()).clear();
}
Also used : SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) CacheManager(org.springframework.cache.CacheManager) LinkedHashMap(java.util.LinkedHashMap) Cache(org.springframework.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 28 with CacheManager

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

the class CachesEndpointTests method namedCacheWithWrongCacheManager.

@Test
void namedCacheWithWrongCacheManager() {
    Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
    cacheManagers.put("test", new ConcurrentMapCacheManager("b", "a"));
    cacheManagers.put("another", new ConcurrentMapCacheManager("c", "a"));
    CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
    CacheEntry entry = endpoint.cache("c", "test");
    assertThat(entry).isNull();
}
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) CacheEntry(org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Aggregations

CacheManager (org.springframework.cache.CacheManager)28 Test (org.junit.jupiter.api.Test)12 ConcurrentMapCacheManager (org.springframework.cache.concurrent.ConcurrentMapCacheManager)10 SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)10 Cache (org.springframework.cache.Cache)8 LinkedHashMap (java.util.LinkedHashMap)5 HazelcastCacheManager (com.hazelcast.spring.cache.HazelcastCacheManager)4 CaffeineCacheManager (org.springframework.cache.caffeine.CaffeineCacheManager)4 EhCacheCacheManager (org.springframework.cache.ehcache.EhCacheCacheManager)4 NoOpCacheManager (org.springframework.cache.support.NoOpCacheManager)4 RedisCacheManager (org.springframework.data.redis.cache.RedisCacheManager)4 JCacheCacheManager (org.springframework.cache.jcache.JCacheCacheManager)3 CouchbaseCacheManager (com.couchbase.client.spring.cache.CouchbaseCacheManager)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 SpringEmbeddedCacheManager (org.infinispan.spring.provider.SpringEmbeddedCacheManager)2 CacheEntry (org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2