Search in sources :

Example 1 with Cache

use of org.springframework.cache.Cache in project imcache by Cetsoft.

the class ImcacheCacheManager method getCache.

/*
     * (non-Javadoc)
     * 
     * @see org.springframework.cache.CacheManager#getCache(java.lang.String)
     */
public Cache getCache(String name) {
    Cache cache = caches.get(name);
    if (cache == null) {
        ImcacheCache newCache = new ImcacheCache(cacheBuilder.build(name));
        final Cache exCache = caches.putIfAbsent(name, newCache);
        if (exCache != null) {
            cache = exCache;
        } else {
            cache = newCache;
        }
    }
    return cache;
}
Also used : Cache(org.springframework.cache.Cache)

Example 2 with Cache

use of org.springframework.cache.Cache 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 3 with Cache

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

the class CacheStatisticsAutoConfigurationTests method doTestCoreStatistics.

private void doTestCoreStatistics(CacheStatisticsProvider provider, boolean supportSize) {
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(cacheStatistics, (supportSize ? 0L : null), null, null);
    getOrCreate(books, "a", "b", "b", "a", "a", "a");
    CacheStatistics updatedCacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, (supportSize ? 2L : null), 0.66D, 0.33D);
}
Also used : CacheStatistics(org.springframework.boot.actuate.cache.CacheStatistics) Cache(org.springframework.cache.Cache)

Example 4 with Cache

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

the class CacheStatisticsAutoConfigurationTests method noOpCacheStatistics.

@Test
public void noOpCacheStatistics() {
    load(NoOpCacheConfig.class);
    CacheStatisticsProvider provider = this.context.getBean("noOpCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(cacheStatistics, null, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, null, null, null);
}
Also used : CacheStatistics(org.springframework.boot.actuate.cache.CacheStatistics) CacheStatisticsProvider(org.springframework.boot.actuate.cache.CacheStatisticsProvider) Cache(org.springframework.cache.Cache) Test(org.junit.Test)

Example 5 with Cache

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

the class CacheAutoConfigurationTests method validateCaffeineCacheWithStats.

private void validateCaffeineCacheWithStats() {
    CaffeineCacheManager cacheManager = validateCacheManager(CaffeineCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
    Cache foo = cacheManager.getCache("foo");
    foo.get("1");
    assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) CouchbaseCache(com.couchbase.client.spring.cache.CouchbaseCache)

Aggregations

Cache (org.springframework.cache.Cache)229 Test (org.junit.jupiter.api.Test)78 Test (org.junit.Test)31 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)30 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)15 CacheManager (org.springframework.cache.CacheManager)11 ArrayList (java.util.ArrayList)10 CaffeineCache (org.springframework.cache.caffeine.CaffeineCache)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 CouchbaseCache (org.springframework.data.couchbase.cache.CouchbaseCache)4 HashMap (java.util.HashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 List (java.util.List)3 RMapCache (org.redisson.api.RMapCache)3 CacheStatistics (org.springframework.boot.actuate.cache.CacheStatistics)3 CaffeineCacheManager (org.springframework.cache.caffeine.CaffeineCacheManager)3 SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)3 Nullable (org.springframework.lang.Nullable)3 SpringCacheBasedAclCache (org.springframework.security.acls.domain.SpringCacheBasedAclCache)3 Lang (com.agiletec.aps.system.services.lang.Lang)2