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;
}
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));
}
}
}
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);
}
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);
}
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);
}
Aggregations