/** See {@link MutableConfiguration#setStoreByValue}. */ public void setStoreByValue(boolean isStoreByValue) { delegate.setStoreByValue(isStoreByValue); }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setStoreByValue(boolean isStoreByVal) { super.setStoreByValue(isStoreByVal); return this; }
public CaffeineConfiguration() { delegate = new MutableConfiguration<>(); delegate.setStoreByValue(false); tickerFactory = SYSTEM_TICKER; executorFactory = COMMON_POOL; copierFactory = JAVA_COPIER; }
<K, V> void createCache(final CacheManager cacheManager, final String cacheName, final Class<K> keyType, final Class<V> valueType) { // All other configuration options come from the ehcache.xml final Configuration configuration = new MutableConfiguration<K, V>().setTypes(keyType, valueType) .setStoreByValue(false); // Store by reference to avoid copying large objects (e.g. catalog) super.createCache(cacheManager, cacheName, configuration); } }
private MutableConfiguration<Object, Object> config() { return new MutableConfiguration<>().setStoreByValue(false) .setManagementEnabled(true).setStatisticsEnabled(true); }
@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; }
public JCacheConfiguration(Configuration<K, V> configuration) { if (configuration != null) { if (configuration instanceof RedissonConfiguration) { configuration = ((RedissonConfiguration<K, V>)configuration).getJcacheConfig(); } if (configuration instanceof CompleteConfiguration) { delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration); } else { delegate = new MutableConfiguration<K, V>(); delegate.setStoreByValue(configuration.isStoreByValue()); delegate.setTypes(configuration.getKeyType(), configuration.getValueType()); } } else { delegate = new MutableConfiguration<K, V>(); } this.expiryPolicy = delegate.getExpiryPolicyFactory().create(); }
public JCacheConfiguration(Configuration<K, V> configuration) { if (configuration != null) { if (configuration instanceof RedissonConfiguration) { configuration = ((RedissonConfiguration<K, V>)configuration).getJcacheConfig(); } if (configuration instanceof CompleteConfiguration) { delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration); } else { delegate = new MutableConfiguration<K, V>(); delegate.setStoreByValue(configuration.isStoreByValue()); delegate.setTypes(configuration.getKeyType(), configuration.getValueType()); } } else { delegate = new MutableConfiguration<K, V>(); } this.expiryPolicy = delegate.getExpiryPolicyFactory().create(); }
@Test public void testTemplateOverridingStoreByRef() throws Exception { cacheManager = cachingProvider.getCacheManager( getClass().getResource("/org/ehcache/docs/ehcache-jsr107-template-override.xml").toURI(), getClass().getClassLoader()); MutableConfiguration<Long, Client> mutableConfiguration = new MutableConfiguration<>(); mutableConfiguration.setTypes(Long.class, Client.class).setStoreByValue(false); Cache<Long, Client> myCache; Client client1 = new Client("client1", 1); myCache = cacheManager.createCache("anotherCache", mutableConfiguration); myCache.put(1L, client1); assertSame(client1, myCache.get(1L)); myCache = cacheManager.createCache("byValCache", mutableConfiguration); myCache.put(1L, client1); assertNotSame(client1, myCache.get(1L)); }
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; }
@Test public void basicConfiguration() throws Exception { // tag::basicConfigurationExample[] CachingProvider provider = Caching.getCachingProvider(); // <1> CacheManager cacheManager = provider.getCacheManager(); // <2> MutableConfiguration<Long, String> configuration = new MutableConfiguration<Long, String>() // <3> .setTypes(Long.class, String.class) // <4> .setStoreByValue(false) // <5> .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); // <6> Cache<Long, String> cache = cacheManager.createCache("jCache", configuration); // <7> cache.put(1L, "one"); // <8> String value = cache.get(1L); // <9> // end::basicConfigurationExample[] assertThat(value, is("one")); }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setStoreByValue(boolean isStoreByVal) { super.setStoreByValue(isStoreByVal); return this; }
public CaffeineConfiguration() { delegate = new MutableConfiguration<>(); delegate.setStoreByValue(false); tickerFactory = SYSTEM_TICKER; executorFactory = COMMON_POOL; copierFactory = JAVA_COPIER; }
/** * {@inheritDoc} */ @Override protected MutableConfiguration<Date, Date> extraSetup(MutableConfiguration<Date, Date> configuration) { return super.extraSetup(configuration).setStoreByValue(false); }
/** * Initialize cache configuration, could be overriden. * * @return * cache default configuration */ protected MutableConfiguration< String, Feature> getFeatureCacheConfiguration() { MutableConfiguration<String, Feature> featuresCacheConfig = new MutableConfiguration<>(); featuresCacheConfig.setTypes(String.class, Feature.class); featuresCacheConfig.setStoreByValue(true); featuresCacheConfig.setStatisticsEnabled(false); return featuresCacheConfig; }
<K, V> void createCache(final CacheManager cacheManager, final String cacheName, final Class<K> keyType, final Class<V> valueType) { // All other configuration options come from the ehcache.xml final Configuration configuration = new MutableConfiguration<K, V>().setTypes(keyType, valueType) .setStoreByValue(false); // Store by reference to avoid copying large objects (e.g. catalog) super.createCache(cacheManager, cacheName, configuration); } }
private Cache<?, ?> createCache(final String exceptionCacheName) { cacheManager.createCache(exceptionCacheName, new MutableConfiguration<Object, Object>().setStoreByValue(false)); return cacheManager.getCache(exceptionCacheName); }
private Cache<String, DomainObject> getCache(CacheManager cacheManager1) { MutableConfiguration<String, DomainObject> config = new MutableConfiguration<String, DomainObject>(); config.setStoreByValue(true) .setTypes(String.class, DomainObject.class) .setStatisticsEnabled(false); return cacheManager1.createCache("cache", config); }
<K, T> Configuration<K, T> createConfiguration(final CacheSizeManager<K, T> listener) { return new MutableConfiguration<K, T>() .setStoreByValue(false) .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(SECONDS, cacheExpiry))) .setManagementEnabled(cacheManagement) .setStatisticsEnabled(cacheStatistics) .addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<>( new FactoryBuilder.SingletonFactory<>(listener), null, false, false)); }