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()));
}
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));
}
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);
}
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;
}
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);
}
Aggregations