use of javax.cache.configuration.MutableConfiguration in project morphium by sboesebeck.
the class MorphiumCacheJCacheImpl method getResultCache.
@SuppressWarnings("CommentedOutCode")
private <T> Cache<Object, CacheEntry<List<T>>> getResultCache(Class<? extends T> type) {
if (resultCaches.containsKey(type)) {
// noinspection unchecked
return resultCaches.get(type);
}
Cache<Object, CacheEntry<List<T>>> cache;
log.info("Creating new cache for " + type.getName());
MutableConfiguration config = new MutableConfiguration<>().setTypes(Object.class, Object.class).setStoreByValue(false).setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf()).setStatisticsEnabled(false);
try {
// noinspection unchecked
cache = getCacheManager().createCache(RESULT_CACHE_NAME + "|" + type.getName(), config);
} catch (Exception e) {
// maybe already there
cache = getCacheManager().getCache(RESULT_CACHE_NAME + "|" + type.getName());
}
// if (!cacheListenerRegistered) {
// try {
// cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<Object, CacheEntry<List<T>>>(
// FactoryBuilder.factoryOf(getClass().getName()), null, false, false));
// } catch (Exception e) {
//
// }
// cacheListenerRegistered=true;
// }
resultCaches.put(type, cache);
return cache;
}
use of javax.cache.configuration.MutableConfiguration in project openEHR_SDK by ehrbase.
the class CachedTemplateProviderTest method find.
@Test
public void find() {
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
MutableConfiguration<String, OPERATIONALTEMPLATE> configuration = new MutableConfiguration<String, OPERATIONALTEMPLATE>().setTypes(String.class, OPERATIONALTEMPLATE.class).setStoreByValue(false);
Cache<String, OPERATIONALTEMPLATE> cache = cacheManager.createCache("jCache", configuration);
CachedTemplateProvider cut = new CachedTemplateProvider(new TestDataTemplateProvider(), cache);
assertTrue(cut.find("ehrbase_blood_pressure_simple.de.v0").isPresent());
// read from Cache
assertTrue(cut.find("ehrbase_blood_pressure_simple.de.v0").isPresent());
}
use of javax.cache.configuration.MutableConfiguration in project ehcache3 by ehcache.
the class Eh107XmlIntegrationTest method test107ExpiryOverriddenByEhcacheTemplateExpiry.
@Test
public void test107ExpiryOverriddenByEhcacheTemplateExpiry() {
final AtomicBoolean expiryFactoryInvoked = new AtomicBoolean(false);
MutableConfiguration<Long, Product> configuration = new MutableConfiguration<>();
configuration.setTypes(Long.class, Product.class);
configuration.setExpiryPolicyFactory(() -> {
expiryFactoryInvoked.set(true);
return new CreatedExpiryPolicy(Duration.FIVE_MINUTES);
});
cacheManager.createCache("productCache3", configuration);
assertThat(expiryFactoryInvoked.get(), is(false));
}
use of javax.cache.configuration.MutableConfiguration in project ehcache3 by ehcache.
the class Eh107XmlIntegrationTest method testTemplateAddsListeners.
@Test
public void testTemplateAddsListeners() throws Exception {
CacheManager cacheManager = cachingProvider.getCacheManager(getClass().getResource("/ehcache-107-listeners.xml").toURI(), getClass().getClassLoader());
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class);
MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(Test107CacheEntryListener::new, null, false, true);
configuration.addCacheEntryListenerConfiguration(listenerConfiguration);
Cache<String, String> cache = cacheManager.createCache("foos", configuration);
cache.put("Hello", "Bonjour");
assertThat(Test107CacheEntryListener.seen.size(), is(1));
assertThat(TestCacheEventListener.seen.size(), is(1));
}
use of javax.cache.configuration.MutableConfiguration in project ehcache3 by ehcache.
the class ConfigurationMergerTest method jsr107ListenerFactoryInitFailureClosesExpiryLoader.
@Test
public void jsr107ListenerFactoryInitFailureClosesExpiryLoader() throws Exception {
ExpiryPolicy expiryPolicy = mock(ExpiryPolicy.class, new MockSettingsImpl<>().extraInterfaces(Closeable.class));
CacheLoader<Object, Object> loader = mock(CacheLoader.class, new MockSettingsImpl<>().extraInterfaces(Closeable.class));
MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>();
configuration.setExpiryPolicyFactory(factoryOf(expiryPolicy)).setReadThrough(true).setCacheLoaderFactory(factoryOf(loader)).addCacheEntryListenerConfiguration(new ThrowingCacheEntryListenerConfiguration());
try {
merger.mergeConfigurations("cache", configuration);
fail("Loader factory should have thrown");
} catch (CacheException mce) {
verify((Closeable) expiryPolicy).close();
verify((Closeable) loader).close();
}
}
Aggregations