@Override public void afterPropertiesSet() { this.cacheManager = Caching.getCachingProvider().getCacheManager( this.cacheManagerUri, this.beanClassLoader, this.cacheManagerProperties); }
/** * @apiNote Access to the standard CacheManager used by `hibernate-jcache` unless * configured differently. */ public static CacheManager locateStandardCacheManager() { // unless configured differently, this is how JCacheRegionFactory // will locate the CacheManager to use return Caching.getCachingProvider().getCacheManager(); } }
@Override public void afterPropertiesSet() { this.cacheManager = Caching.getCachingProvider().getCacheManager( this.cacheManagerUri, this.beanClassLoader, this.cacheManagerProperties); }
@Override public void afterPropertiesSet() { if (getCacheManager() == null) { setCacheManager(Caching.getCachingProvider().getCacheManager()); } super.afterPropertiesSet(); }
@Test public void getCache() { Cache<Integer, Integer> cache = Caching.getCachingProvider() .getCacheManager().getCache("test-cache"); assertThat(cache, is(not(nullValue()))); @SuppressWarnings("unchecked") CaffeineConfiguration<Integer, Integer> config = cache.getConfiguration(CaffeineConfiguration.class); checkTestCache(config); }
@Override public void afterPropertiesSet() { if (getCacheManager() == null) { setCacheManager(Caching.getCachingProvider().getCacheManager()); } super.afterPropertiesSet(); }
@BeforeClass(alwaysRun = true) public void beforeClass() { CachingProvider provider = Caching.getCachingProvider(CaffeineCachingProvider.class.getName()); cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); }
@BeforeClass public void beforeClass() { CachingProvider provider = Caching.getCachingProvider(PROVIDER_NAME); cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); }
@Bean public CacheManager jCacheManager() { CacheManager cacheManager = this.cachingProvider.getCacheManager(); MutableConfiguration<Object, Object> mutableConfiguration = new MutableConfiguration<>(); mutableConfiguration.setStoreByValue(false); // otherwise value has to be Serializable cacheManager.createCache("testCache", mutableConfiguration); cacheManager.createCache("primary", mutableConfiguration); cacheManager.createCache("secondary", mutableConfiguration); return cacheManager; }
@Before public void setUp() throws Exception { cachingProvider = Caching.getCachingProvider(); cacheManager = cachingProvider.getCacheManager(getClass().getResource("/ehcache-107-integration.xml") .toURI(), cachingProvider.getDefaultClassLoader()); }
@Test public void testJCacheClustered() throws Exception { URL xml = CacheManagerLifecycleEhcacheIntegrationTest.class.getResource("/configs/jcache-clustered.xml"); URL substitutedXml = substitute(xml, "cluster-uri", CLUSTER.getConnectionURI().toString()); CachingProvider cachingProvider = Caching.getCachingProvider(); cachingProvider.getCacheManager(substitutedXml.toURI(), getClass().getClassLoader()); } }
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()); }
/** Resolves the annotations to the provider as multiple are on the IDE's classpath. */ void configureCachingProvider() { CachingProvider provider = Caching.getCachingProvider( CaffeineCachingProvider.class.getName()); CacheManager cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); bind(CacheResolverFactory.class).toInstance(new DefaultCacheResolverFactory(cacheManager)); bind(CacheManager.class).toInstance(cacheManager); } }
@Test public void sanity() { CachingProvider cachingProvider = Caching.getCachingProvider( "com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider", getClass().getClassLoader()); Cache<String, Integer> cache = cachingProvider.getCacheManager() .getCache("test-cache-2", String.class, Integer.class); assertNull(cache.get("a")); } }
@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); }
@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)); }
@Test public void testCacheLevelOnlyOneOverridesCacheManagerLevel() throws Exception { CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/org/ehcache/docs/ehcache-107-mbeans-cache-manager-config.xml") .toURI(), provider.getDefaultClassLoader()); Cache<String, String> cache = cacheManager.getCache("overrideOneCache", String.class, String.class); @SuppressWarnings("unchecked") Eh107Configuration<String, String> configuration = cache.getConfiguration(Eh107Configuration.class); assertThat(configuration.isManagementEnabled(), is(true)); assertThat(configuration.isStatisticsEnabled(), is(false)); assertThat(isMbeanRegistered("overrideOneCache", MBEAN_MANAGEMENT_TYPE), is(true)); assertThat(isMbeanRegistered("overrideOneCache", MBEAN_STATISTICS_TYPE), is(false)); }
@Before public void setup() { this.cacheManager = getCachingProvider().getCacheManager(); this.cacheManager.createCache(CACHE_NAME, new MutableConfiguration<>()); this.cacheManager.createCache(CACHE_NAME_NO_NULL, new MutableConfiguration<>()); this.nativeCache = this.cacheManager.getCache(CACHE_NAME); this.cache = new JCacheCache(this.nativeCache); Cache<Object, Object> nativeCacheNoNull = this.cacheManager.getCache(CACHE_NAME_NO_NULL); this.cacheNoNull = new JCacheCache(nativeCacheNoNull, false); }
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; }
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; }