Search in sources :

Example 1 with CacheManager

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

the class CachePublicMetrics method addMetrics.

private void addMetrics(Collection<Metric<?>> metrics, String cacheName, List<CacheManagerBean> cacheManagerBeans) {
    for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
        CacheManager cacheManager = cacheManagerBean.getCacheManager();
        Cache cache = cacheManager.getCache(cacheName);
        CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
        if (statistics != null) {
            String prefix = cacheName;
            if (cacheManagerBeans.size() > 1) {
                prefix = cacheManagerBean.getBeanName() + "_" + prefix;
            }
            prefix = "cache." + prefix + (prefix.endsWith(".") ? "" : ".");
            metrics.addAll(statistics.toMetrics(prefix));
        }
    }
}
Also used : CacheStatistics(org.springframework.boot.actuate.cache.CacheStatistics) CacheManager(org.springframework.cache.CacheManager) Cache(org.springframework.cache.Cache)

Example 2 with CacheManager

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

the class CacheAutoConfigurationTests method testCustomizers.

@SuppressWarnings("rawtypes")
private void testCustomizers(Class<?> config, String cacheType, String... expectedCustomizerNames) {
    load(config, "spring.cache.type=" + cacheType);
    CacheManager cacheManager = validateCacheManager(CacheManager.class);
    List<String> expected = new ArrayList<>();
    expected.addAll(Arrays.asList(expectedCustomizerNames));
    Map<String, CacheManagerTestCustomizer> map = this.context.getBeansOfType(CacheManagerTestCustomizer.class);
    for (Map.Entry<String, CacheManagerTestCustomizer> entry : map.entrySet()) {
        if (expected.contains(entry.getKey())) {
            expected.remove(entry.getKey());
            assertThat(entry.getValue().cacheManager).isSameAs(cacheManager);
        } else {
            assertThat(entry.getValue().cacheManager).isNull();
        }
    }
    assertThat(expected).hasSize(0);
}
Also used : ArrayList(java.util.ArrayList) CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) EhCacheCacheManager(org.springframework.cache.ehcache.EhCacheCacheManager) CouchbaseCacheManager(com.couchbase.client.spring.cache.CouchbaseCacheManager) SpringEmbeddedCacheManager(org.infinispan.spring.provider.SpringEmbeddedCacheManager) NoOpCacheManager(org.springframework.cache.support.NoOpCacheManager) HazelcastCacheManager(com.hazelcast.spring.cache.HazelcastCacheManager) CacheManager(org.springframework.cache.CacheManager) RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Map(java.util.Map)

Example 3 with CacheManager

use of org.springframework.cache.CacheManager in project thingsboard by thingsboard.

the class CaffeineCacheConfiguration method cacheManager.

@Bean
public CacheManager cacheManager() {
    SimpleCacheManager manager = new SimpleCacheManager();
    if (specs != null) {
        List<CaffeineCache> caches = specs.entrySet().stream().map(entry -> buildCache(entry.getKey(), entry.getValue())).collect(Collectors.toList());
        manager.setCaches(caches);
    }
    return manager;
}
Also used : Ticker(com.github.benmanes.caffeine.cache.Ticker) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) KeyGenerator(org.springframework.cache.interceptor.KeyGenerator) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CacheManager(org.springframework.cache.CacheManager) Map(java.util.Map) Data(lombok.Data) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) EnableCaching(org.springframework.cache.annotation.EnableCaching) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Bean(org.springframework.context.annotation.Bean)

Example 4 with CacheManager

use of org.springframework.cache.CacheManager in project tutorials by eugenp.

the class CacheConfiguration method cacheManager.

@Bean
public CacheManager cacheManager(HazelcastInstance hazelcastInstance) {
    log.debug("Starting HazelcastCacheManager");
    CacheManager cacheManager = new com.hazelcast.spring.cache.HazelcastCacheManager(hazelcastInstance);
    return cacheManager;
}
Also used : CacheManager(org.springframework.cache.CacheManager)

Example 5 with CacheManager

use of org.springframework.cache.CacheManager in project tutorials by eugenp.

the class CacheConfiguration method cacheManager.

@Bean
public CacheManager cacheManager(HazelcastInstance hazelcastInstance) {
    log.debug("Starting HazelcastCacheManager");
    CacheManager cacheManager = new com.hazelcast.spring.cache.HazelcastCacheManager(hazelcastInstance);
    return cacheManager;
}
Also used : CacheManager(org.springframework.cache.CacheManager)

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