@Override public <K, V> CacheProxy<K, V> getCache(String cacheName) { requireNonNull(cacheName); requireNotClosed(); CacheProxy<?, ?> cache = caches.computeIfAbsent(cacheName, name -> { CacheProxy<?, ?> created = cacheFactory.tryToCreateFromExternalSettings(name); if (created != null) { created.enableManagement(created.getConfiguration().isManagementEnabled()); created.enableStatistics(created.getConfiguration().isStatisticsEnabled()); } return created; }); @SuppressWarnings("unchecked") CacheProxy<K, V> castedCache = (CacheProxy<K, V>) cache; return castedCache; }
static void checkTestCache(CaffeineConfiguration<?, ?> config) { checkStoreByValue(config); checkListener(config); assertThat(config.getKeyType(), is(Object.class)); assertThat(config.getValueType(), is(Object.class)); assertThat(config.getCacheLoaderFactory().create(), instanceOf(TestCacheLoader.class)); assertThat(config.getCacheWriter(), instanceOf(TestCacheWriter.class)); assertThat(config.isStatisticsEnabled(), is(true)); assertThat(config.isManagementEnabled(), is(true)); checkSize(config); checkRefresh(config); checkLazyExpiration(config); checkEagerExpiration(config); }
@Override public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache( String cacheName, C configuration) { requireNotClosed(); requireNonNull(configuration); CacheProxy<?, ?> cache = caches.compute(cacheName, (name, existing) -> { if ((existing != null) && !existing.isClosed()) { throw new CacheException("Cache " + cacheName + " already exists"); } else if (cacheFactory.isDefinedExternally(cacheName)) { throw new CacheException("Cache " + cacheName + " is configured externally"); } return cacheFactory.createCache(cacheName, configuration); }); enableManagement(cache.getName(), cache.getConfiguration().isManagementEnabled()); enableStatistics(cache.getName(), cache.getConfiguration().isStatisticsEnabled()); @SuppressWarnings("unchecked") Cache<K, V> castedCache = (Cache<K, V>) cache; return castedCache; }
@Override public <K, V> CacheProxy<K, V> getCache(String cacheName) { requireNonNull(cacheName); requireNotClosed(); CacheProxy<?, ?> cache = caches.computeIfAbsent(cacheName, name -> { CacheProxy<?, ?> created = cacheFactory.tryToCreateFromExternalSettings(name); if (created != null) { created.enableManagement(created.getConfiguration().isManagementEnabled()); created.enableStatistics(created.getConfiguration().isStatisticsEnabled()); } return created; }); @SuppressWarnings("unchecked") CacheProxy<K, V> castedCache = (CacheProxy<K, V>) cache; return castedCache; }
@Override public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache( String cacheName, C configuration) { requireNotClosed(); requireNonNull(configuration); CacheProxy<?, ?> cache = caches.compute(cacheName, (name, existing) -> { if ((existing != null) && !existing.isClosed()) { throw new CacheException("Cache " + cacheName + " already exists"); } else if (cacheFactory.isDefinedExternally(cacheName)) { throw new CacheException("Cache " + cacheName + " is configured externally"); } return cacheFactory.createCache(cacheName, configuration); }); enableManagement(cache.getName(), cache.getConfiguration().isManagementEnabled()); enableStatistics(cache.getName(), cache.getConfiguration().isStatisticsEnabled()); @SuppressWarnings("unchecked") Cache<K, V> castedCache = (Cache<K, V>) cache; return castedCache; }