Search in sources :

Example 66 with MutableConfiguration

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;
}
Also used : CacheEntry(de.caluga.morphium.cache.jcache.CacheEntry) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 67 with MutableConfiguration

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());
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 68 with MutableConfiguration

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Product(com.pany.domain.Product) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

Example 69 with MutableConfiguration

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));
}
Also used : MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) CacheManager(javax.cache.CacheManager) Test107CacheEntryListener(com.pany.ehcache.Test107CacheEntryListener) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

Example 70 with MutableConfiguration

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();
    }
}
Also used : CacheException(javax.cache.CacheException) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Closeable(java.io.Closeable) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)145 Test (org.junit.Test)97 CacheManager (javax.cache.CacheManager)75 CachingProvider (javax.cache.spi.CachingProvider)35 Cache (javax.cache.Cache)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 Test (org.junit.jupiter.api.Test)12 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)11 URI (java.net.URI)11 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)11 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)10 Duration (javax.cache.expiry.Duration)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)7 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)7 AssertTask (com.hazelcast.test.AssertTask)6 BaseTest (org.redisson.BaseTest)6 RedisRunner (org.redisson.RedisRunner)6