Search in sources :

Example 21 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project wcomponents by BorderTech.

the class VelocityCacheImpl method getCache.

/**
 * @return the cache instance
 */
protected synchronized Cache<Object, Resource> getCache() {
    Cache<Object, Resource> cache = Caching.getCache(CACHE_NAME, Object.class, Resource.class);
    if (cache == null) {
        final CacheManager mgr = Caching.getCachingProvider().getCacheManager();
        MutableConfiguration<Object, Resource> config = new MutableConfiguration<>();
        config.setTypes(Object.class, Resource.class);
        config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));
        // Velocity template classes are not serializable so use by ref.
        config.setStoreByValue(false);
        cache = mgr.createCache(CACHE_NAME, config);
    }
    return cache;
}
Also used : Resource(org.apache.velocity.runtime.resource.Resource) CacheManager(javax.cache.CacheManager) Duration(javax.cache.expiry.Duration) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 22 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project Payara by payara.

the class PayaraCacheResolverFactory method getExceptionCacheResolver.

@Override
public CacheResolver getExceptionCacheResolver(CacheMethodDetails<CacheResult> cmd) {
    CacheResult result = cmd.getCacheAnnotation();
    String cacheName = result.exceptionCacheName();
    Cache cache = cacheManager.getCache(cacheName);
    if ((cache == null)) {
        cache = cacheManager.createCache(cacheName, new MutableConfiguration<Object, Object>());
    }
    return new PayaraCacheResolver(cache);
}
Also used : CacheResult(javax.cache.annotation.CacheResult) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache)

Example 23 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.

the class CacheManagerTest method create_cache2k_config_key_type_mismatch.

@Test(expected = IllegalArgumentException.class)
public void create_cache2k_config_key_type_mismatch() {
    CachingProvider p = Caching.getCachingProvider();
    CacheManager cm = p.getCacheManager();
    MutableConfiguration cfg = ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>() {
    });
    Cache<Integer, Double> cache = cm.createCache("aCache", cfg.setTypes(Integer.class, Double.class));
    cache.close();
}
Also used : CacheManager(javax.cache.CacheManager) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 24 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project tutorials by eugenp.

the class CacheLoaderTest method setup.

@Before
public void setup() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setReadThrough(true).setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(new SimpleCacheLoader()));
    this.cache = cacheManager.createCache("SimpleCache", config);
}
Also used : CacheManager(javax.cache.CacheManager) FactoryBuilder(javax.cache.configuration.FactoryBuilder) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Before(org.junit.Before)

Example 25 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project tutorials by eugenp.

the class JCacheIntegrationTest method instantiateCache.

@Test
public void instantiateCache() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<String, String> config = new MutableConfiguration<>();
    Cache<String, String> cache = cacheManager.createCache("simpleCache", config);
    cache.put("key1", "value1");
    cache.put("key2", "value2");
    assertEquals("value1", cache.get("key1"));
    assertEquals("value2", cache.get("key2"));
    cacheManager.close();
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)118 Test (org.junit.Test)72 CacheManager (javax.cache.CacheManager)67 Cache (javax.cache.Cache)32 CachingProvider (javax.cache.spi.CachingProvider)27 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 Duration (javax.cache.expiry.Duration)10 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)7 AssertTask (com.hazelcast.test.AssertTask)6 BaseTest (org.redisson.BaseTest)6 RedisRunner (org.redisson.RedisRunner)6 RedisProcess (org.redisson.RedisRunner.RedisProcess)6 JCacheManager (org.infinispan.jcache.embedded.JCacheManager)5