Search in sources :

Example 76 with MutableConfiguration

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

the class TypesTest method genericsEnforcementAndStricterTypeEnforcementFromCaching.

/**
 * Same as above but using the shorthand Caching to acquire.
 * Should work the same.
 */
@Test
public void genericsEnforcementAndStricterTypeEnforcementFromCaching() {
    // configure the cache
    MutableConfiguration config = new MutableConfiguration<>();
    config.setTypes(Identifier.class, Hound.class);
    Cache<Identifier, Dog> cache = cacheManager.createCache(cacheName, config);
    // Types are restricted and types are enforced
    // Cannot put in wrong types
    // cache.put(1, "something");
    // can put in
    cache.put(pistachio.getName(), pistachio);
    // can put in with generics but possibly not with configuration as not a hound
    try {
        cache.put(tonto.getName(), tonto);
    } catch (ClassCastException e) {
    // expected but not mandatory. The RI throws these.
    }
    // cannot get out wrong key types
    // assertNotNull(cache.get(1));
    assertNotNull(cache.get(pistachio.getName()));
    // not necessarily
    // assertNotNull(cache.get(tonto.getName()));
    // cannot remove wrong key types
    // assertTrue(cache.remove(1));
    assertTrue(cache.remove(pistachio.getName()));
// not necessarily
// assertTrue(cache.remove(tonto.getName()));
}
Also used : Identifier(domain.Identifier) Dog(domain.Dog) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

Example 77 with MutableConfiguration

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

the class CacheManagerManagementTest method testCacheStatisticsOffThenOnThenOff.

@Test
public void testCacheStatisticsOffThenOnThenOff() throws Exception {
    MutableConfiguration configuration = new MutableConfiguration();
    configuration.setStatisticsEnabled(false);
    cacheManager.createCache("cache1", configuration);
    cacheManager.createCache("cache2", configuration);
    Set<? extends ObjectName> names = mBeanServer.queryNames(new ObjectName("javax.cache:*"), null);
    Assert.assertTrue(names.size() == 0);
    configuration.setStatisticsEnabled(true);
    cacheManager.createCache("cache3", configuration);
    cacheManager.createCache("cache4", configuration);
    assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));
    cacheManager.enableStatistics("cache3", false);
    assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(1));
    cacheManager.enableStatistics("cache3", true);
    assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));
}
Also used : MutableConfiguration(javax.cache.configuration.MutableConfiguration) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 78 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project micrometer by micrometer-metrics.

the class JCacheMetricsCompatibilityTest method createCache.

@Override
public Cache<String, String> createCache() {
    CacheManager cacheManager = new RICachingProvider().getCacheManager();
    MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
    configuration.setTypes(String.class, String.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
    return cacheManager.createCache("mycache", configuration);
}
Also used : RICachingProvider(org.jsr107.ri.spi.RICachingProvider) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 79 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project micronaut-core by micronaut-projects.

the class CacheFactory method cacheManager.

@Singleton
CacheManager cacheManager() {
    CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
    cacheManager.createCache("my-cache", new MutableConfiguration());
    return cacheManager;
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Singleton(jakarta.inject.Singleton)

Example 80 with MutableConfiguration

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

the class PayaraCacheResolverFactory method getCacheResolver.

@Override
public CacheResolver getCacheResolver(CacheMethodDetails<? extends Annotation> cmd) {
    String cacheName = cmd.getCacheName();
    Cache cache = cacheManager.getCache(cacheName);
    if ((cache == null)) {
        cache = cacheManager.createCache(cacheName, new MutableConfiguration<Object, Object>());
    }
    return new PayaraCacheResolver(cache);
}
Also used : MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)146 Test (org.junit.Test)97 CacheManager (javax.cache.CacheManager)76 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