Refine search
@Test public void testTypeOverriding() throws Exception { CachingProvider provider = Caching.getCachingProvider(); javax.cache.CacheManager cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-107-types.xml").toURI(), getClass().getClassLoader()); MutableConfiguration<Long, String> cache1Conf = new MutableConfiguration<>(); cache1Conf.setTypes(Long.class, String.class); javax.cache.Cache<Long, String> cache = cacheManager.createCache("defaultCache", cache1Conf); @SuppressWarnings("unchecked") Configuration<Long, String> cache1CompleteConf = cache.getConfiguration(Configuration.class); assertThat(cache1CompleteConf.getKeyType(), is(equalTo(Long.class))); assertThat(cache1CompleteConf.getValueType(), is(equalTo(String.class))); }
public JCache(URL url) { String method = url.getParameter(Constants.METHOD_KEY, ""); String key = url.getAddress() + "." + url.getServiceKey() + "." + method; // jcache parameter is the full-qualified class name of SPI implementation String type = url.getParameter("jcache"); CachingProvider provider = StringUtils.isEmpty(type) ? Caching.getCachingProvider() : Caching.getCachingProvider(type); CacheManager cacheManager = provider.getCacheManager(); Cache<Object, Object> cache = cacheManager.getCache(key); if (cache == null) { try { //configure the cache MutableConfiguration config = new MutableConfiguration<Object, Object>() .setTypes(Object.class, Object.class) .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000)))) .setStoreByValue(false) .setManagementEnabled(true) .setStatisticsEnabled(true); cache = cacheManager.createCache(key, config); } catch (CacheException e) { // concurrent cache initialization cache = cacheManager.getCache(key); } } this.store = cache; }
@Test public void testRunTimeTypeLaxity() throws Exception { CachingProvider provider = Caching.getCachingProvider(); javax.cache.CacheManager cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-107-types.xml").toURI(), getClass().getClassLoader()); MutableConfiguration<Long, String> cache1Conf = new MutableConfiguration<>(); cache1Conf.setTypes(Long.class, String.class); javax.cache.Cache<Long, String> cache = cacheManager.createCache("cache1", cache1Conf); @SuppressWarnings("unchecked") Configuration<Long, String> cache1CompleteConf = cache.getConfiguration(Configuration.class); assertThat(cache1CompleteConf.getKeyType(), is(equalTo(Long.class))); assertThat(cache1CompleteConf.getValueType(), is(equalTo(String.class))); try { cacheManager.getCache("cache1"); } finally { cacheManager.destroyCache("cache1"); cacheManager.close(); } }
@Test public void testCacheManagerCloseLenientToEhcacheClosed() throws Exception { CachingProvider provider = Caching.getCachingProvider(); javax.cache.CacheManager cacheManager = provider.getCacheManager(this.getClass() .getResource("/ehcache-107-types.xml") .toURI(), getClass().getClassLoader()); MutableConfiguration<Long, String> cache1Conf = new MutableConfiguration<>(); javax.cache.Cache<Long, String> cache = cacheManager.createCache("cache1", cache1Conf); cacheManager.unwrap(org.ehcache.CacheManager.class).removeCache(cache.getName()); cacheManager.close(); } }
Class<V> valueType) { return getCachingProvider().getCacheManager().getCache(cacheName, keyType, valueType);
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); CachingProvider provider = Caching.getCachingProvider(); cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-loader-writer-107-load-atomics.xml").toURI(), getClass().getClassLoader()); testCache = cacheManager.createCache("testCache", new MutableConfiguration<Number, CharSequence>() .setReadThrough(true) .setWriteThrough(true) .setCacheLoaderFactory(() -> cacheLoader) .setCacheWriterFactory(() -> cacheWriter) .setTypes(Number.class, CharSequence.class)); }
protected Cache<String, UserIdentityClaimsDO> getCache() { CacheManager manager = Caching.getCacheManagerFactory().getCacheManager(InMemoryIdentityDataStore.IDENTITY_LOGIN_DATA_CACHE_MANAGER); Cache<String, UserIdentityClaimsDO> cache = manager.getCache(InMemoryIdentityDataStore.IDENTITY_LOGIN_DATA_CACHE); return cache; }
JCacheProfiler() { random = new Random(); count = new LongAdder(); CachingProvider provider = Caching.getCachingProvider(CaffeineCachingProvider.class.getName()); CacheManager cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); cache = cacheManager.createCache("profiler", new MutableConfiguration<>()); executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setPriority(Thread.MIN_PRIORITY).setDaemon(true).build()); }
@BeforeClass public void beforeClass() { final CachingProvider provider = Caching.getCachingProvider(PROVIDER_NAME); cacheManager = provider.getCacheManager(); cacheManager.destroyCache("cache-not-in-config-file"); cacheConfig = new MutableConfiguration<>(); cacheConfig.setTypes(String.class, String.class); cacheConfig.setStatisticsEnabled(true); }
/** * get the cache manager * @return */ private static Cache getAppContextVersionConfigCache() { return Caching.getCacheManager(AppMConstants.APP_CONTEXT_VERSION_CACHE_MANAGER) .getCache(AppMConstants.APP_CONTEXT_VERSION_CONFIG_CACHE); }
@Test public void testLoaderConfiguration() throws Exception { final AtomicBoolean loaderCreated = new AtomicBoolean(false); MutableConfiguration<String, String> configuration = new MutableConfiguration<>(); configuration.setTypes(String.class, String.class).setReadThrough(true); configuration.setCacheLoaderFactory(() -> { loaderCreated.set(true); return new TestCacheLoader(); }); CachingProvider provider = Caching.getCachingProvider(); CacheManager cacheManager = provider.getCacheManager(); Cache<String, String> cache = cacheManager.createCache("cache", configuration); assertThat(loaderCreated.get(), is(true)); cache.putIfAbsent("42", "The Answer"); TestCacheLoader.seen.clear(); CompletionListenerFuture future = new CompletionListenerFuture(); cache.loadAll(Collections.singleton("42"), true, future); future.get(); assertThat(TestCacheLoader.seen, contains("42")); }
@Test public void testIterateExpiredReturnsNull() throws Exception { EhcacheCachingProvider provider = (EhcacheCachingProvider) Caching.getCachingProvider(); TestTimeSource testTimeSource = new TestTimeSource(); TimeSourceConfiguration timeSourceConfiguration = new TimeSourceConfiguration(testTimeSource); CacheManager cacheManager = provider.getCacheManager(new URI("test://testIterateExpiredReturnsNull"), new DefaultConfiguration(getClass().getClassLoader(), timeSourceConfiguration)); Cache<Number, CharSequence> testCache = cacheManager.createCache("testCache", new MutableConfiguration<Number, CharSequence>() .setExpiryPolicyFactory(() -> new ExpiryPolicy() { @Override public Duration getExpiryForCreation() { .setTypes(Number.class, CharSequence.class)); cacheManager.close();
@Override public void afterPropertiesSet() { this.cacheManager = Caching.getCachingProvider().getCacheManager( this.cacheManagerUri, this.beanClassLoader, this.cacheManagerProperties); }
@Test public void testXAWorksWithJsr107() throws Exception { BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); URI uri = getClass().getResource("/configs/simple-xa.xml").toURI(); CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, getClass().getClassLoader()); Cache<String, String> xaCache = cacheManager.getCache("xaCache", String.class, String.class); transactionManager.begin(); { xaCache.put("key", "one"); } transactionManager.commit(); cacheManager.close(); }
@Bean @Override public CacheManager cacheManager() { javax.cache.CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(); MutableConfiguration<Object, Object> mutableConfiguration = new MutableConfiguration<Object, Object>(); mutableConfiguration.setStoreByValue(false); // otherwise value has to be Serializable cacheManager.createCache("user", mutableConfiguration); cacheManager.createCache("user2", mutableConfiguration); cacheManager.createCache("user3", mutableConfiguration); JCacheCacheManager jCacheCacheManager = new JCacheCacheManager(cacheManager); return jCacheCacheManager; }
@BeforeClass public void beforeClass() { CachingProvider provider = Caching.getCachingProvider(PROVIDER_NAME); cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); }
@Override public synchronized <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass, final Configuration<K, V> config) { Cache<K, V> cache = Caching.getCache(name, keyClass, valueClass); if (cache == null) { final CacheManager mgr = Caching.getCachingProvider().getCacheManager(); cache = mgr.createCache(name, config); } return cache; }
/** * */ @Test public void testStartIgnite() { javax.cache.spi.CachingProvider cachingProvider = Caching.getCachingProvider(); assert cachingProvider instanceof CachingProvider; CacheManager cacheMgr = cachingProvider.getCacheManager(); assertEquals(Collections.<String>emptySet(), Sets.newHashSet(cacheMgr.getCacheNames())); Cache<Integer, String> cacheA = cacheMgr.createCache("a", new CacheConfiguration()); cacheA.put(1, "1"); assertEquals("1", cacheA.get(1)); cacheMgr.createCache("b", new CacheConfiguration()); assertEquals(Sets.newHashSet("a", "b"), Sets.newHashSet(cacheMgr.getCacheNames())); cacheMgr.destroyCache("a"); cacheMgr.destroyCache("b"); assertEquals(Collections.<String>emptySet(), Sets.newHashSet(cacheMgr.getCacheNames())); }
@Test public void testDefaultUriOverride() throws Exception { URI override = getClass().getResource("/ehcache-107.xml").toURI(); Properties props = new Properties(); props.put(DefaultConfigurationResolver.DEFAULT_CONFIG_PROPERTY_NAME, override); CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(null, null, props); assertEquals(override, cacheManager.getURI()); Caching.getCachingProvider().close(); }
@Before public void setUp() throws Exception { cachingProvider = Caching.getCachingProvider(); cacheManager = cachingProvider.getCacheManager(getClass().getResource("/ehcache-107-integration.xml") .toURI(), cachingProvider.getDefaultClassLoader()); }