Java Code Examples for javax.cache.configuration.MutableConfiguration#setStoreByValue()

The following examples show how to use javax.cache.configuration.MutableConfiguration#setStoreByValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JCacheEhCacheAnnotationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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;
}
 
Example 2
Source File: JCacheEhCacheAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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;
}
 
Example 3
Source File: CachingPrincipalAttributesRepository.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Prep cache configuration.
 *
 * @param expiryDuration the expiry duration
 * @return the mutable configuration
 */
protected static MutableConfiguration<String, Map<String, Object>> createCacheConfiguration(final Duration expiryDuration) {
    final MutableConfiguration<String, Map<String, Object>> config = new MutableConfiguration<>();
    config.setStatisticsEnabled(true);
    config.setManagementEnabled(true);
    config.setStoreByValue(true);
    config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(expiryDuration));
    return config;
}
 
Example 4
Source File: JCacheEhCacheAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager jCacheManager() {
	CacheManager cacheManager = this.cachingProvider.getCacheManager();
	MutableConfiguration<Object, Object> mutableConfiguration = new MutableConfiguration<Object, Object>();
	mutableConfiguration.setStoreByValue(false);  // otherwise value has to be Serializable
	cacheManager.createCache("testCache", mutableConfiguration);
	cacheManager.createCache("primary", mutableConfiguration);
	cacheManager.createCache("secondary", mutableConfiguration);
	return cacheManager;
}
 
Example 5
Source File: JCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpiration() throws InterruptedException, IllegalArgumentException, URISyntaxException, FailedToStartRedisException, IOException {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .port(6311)
            .run();

    MutableConfiguration<String, String> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
    config.setStoreByValue(true);
    
    URI configUri = getClass().getResource("redisson-jcache.json").toURI();
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager(configUri, null)
            .createCache("test", config);

    CountDownLatch latch = new CountDownLatch(1);
    
    String key = "123";
    ExpiredListener clientListener = new ExpiredListener(latch, key, "90");
    MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = 
            new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(clientListener), null, true, true);
    cache.registerCacheEntryListener(listenerConfiguration);

    cache.put(key, "90");
    Assert.assertNotNull(cache.get(key));
    
    latch.await();
    
    Assert.assertNull(cache.get(key));
    
    cache.close();
    runner.stop();
}
 
Example 6
Source File: CacheMXBeanTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomConfiguration() throws Exception {
  boolean storeByValue = false;
  MutableConfiguration configuration = new MutableConfiguration()
      .setReadThrough(false).setWriteThrough(false).setStoreByValue(storeByValue)
      .setTypes(java.math.BigDecimal.class, java.awt.Color.class)
      .setManagementEnabled(true).setStatisticsEnabled(false);
  Cache cache = null;
  try
  {
    cache = getCacheManager().createCache("customCache", configuration);
  } catch (UnsupportedOperationException e) {
    storeByValue = true;
    configuration.setStoreByValue(storeByValue);
    cache = getCacheManager().createCache("customCache", configuration);
  }
  assertEquals("java.math.BigDecimal", lookupManagementAttribute(cache, CacheConfiguration, "KeyType"));
  assertEquals("java.awt.Color", lookupManagementAttribute(cache, CacheConfiguration, "ValueType"));
  assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "ReadThrough"));
  assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "WriteThrough"));
  assertEquals(storeByValue, lookupManagementAttribute(cache, CacheConfiguration, "StoreByValue"));
  assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "StatisticsEnabled"));
  assertEquals(true, lookupManagementAttribute(cache, CacheConfiguration, "ManagementEnabled"));

  //this used to just call close() but that does not work if an implementation maintains statistics on the cluster.
  cache.getCacheManager().destroyCache("customCache");
}
 
Example 7
Source File: JCacheBuilder.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void setConfiguration(Configuration<K,V> cfg) {
  if (cfg instanceof CompleteConfiguration) {
    config = (CompleteConfiguration<K,V>) cfg;
    if (cfg instanceof ExtendedConfiguration) {
      cache2kConfiguration = ((ExtendedConfiguration<K,V>) cfg).getCache2kConfiguration();
      if (cache2kConfiguration != null) {
        if (cache2kConfiguration.getName() != null && !cache2kConfiguration.getName().equals(name)) {
          throw new IllegalArgumentException("cache name mismatch.");
        }
        cache2kConfigurationWasProvided = true;
      }
    }
  } else {
    MutableConfiguration<K, V> _cfgCopy = new MutableConfiguration<K, V>();
    _cfgCopy.setTypes(cfg.getKeyType(), cfg.getValueType());
    _cfgCopy.setStoreByValue(cfg.isStoreByValue());
    config = _cfgCopy;
  }
  if (cache2kConfiguration == null) {
    cache2kConfiguration = CacheManagerImpl.PROVIDER.getDefaultConfiguration(manager.getCache2kManager());
    if (cfg instanceof ExtendedMutableConfiguration) {
      ((ExtendedMutableConfiguration) cfg).setCache2kConfiguration(cache2kConfiguration);
    }
  }
  cache2kConfiguration.setName(name);
  Cache2kCoreProviderImpl.CACHE_CONFIGURATION_PROVIDER.augmentConfiguration(manager.getCache2kManager(), cache2kConfiguration);
  cache2kConfigurationWasProvided |= cache2kConfiguration.isExternalConfigurationPresent();
  if (cache2kConfigurationWasProvided) {
    extraConfiguration = CACHE2K_DEFAULTS;
    JCacheConfiguration _extraConfigurationSpecified =
      cache2kConfiguration.getSections().getSection(JCacheConfiguration.class);
    if (_extraConfigurationSpecified != null) {
      extraConfiguration = _extraConfigurationSpecified;
    }
  }
}
 
Example 8
Source File: JCacheAdapter.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <C extends Configuration<K, V>> C getConfiguration(Class<C> _class) {
  if (CompleteConfiguration.class.isAssignableFrom(_class)) {
    MutableConfiguration<K, V> cfg = new MutableConfiguration<K, V>();
    cfg.setTypes(keyType, valueType);
    cfg.setStatisticsEnabled(jmxStatisticsEnabled);
    cfg.setManagementEnabled(jmxEnabled);
    cfg.setStoreByValue(storeByValue);
    Collection<CacheEntryListenerConfiguration<K,V>> _listenerConfigurations = eventHandling.getAllListenerConfigurations();
    for (CacheEntryListenerConfiguration<K,V> _listenerConfig : _listenerConfigurations) {
      cfg.addCacheEntryListenerConfiguration(_listenerConfig);
    }
    return (C) cfg;
  }
  return (C) new Configuration<K, V>() {
    @Override
    public Class<K> getKeyType() {
      return keyType;
    }

    @Override
    public Class<V> getValueType() {
      return valueType;
    }

    @Override
    public boolean isStoreByValue() {
      return storeByValue;
    }
  };
}
 
Example 9
Source File: CacheMXBeanTest.java    From cache2k with Apache License 2.0 4 votes vote down vote up
@Override
protected MutableConfiguration<Long, String> extraSetup(MutableConfiguration<Long, String> configuration) {
  return configuration.setStoreByValue(true);
}
 
Example 10
Source File: CacheMBStatisticsBeanTest.java    From cache2k with Apache License 2.0 4 votes vote down vote up
@Override
protected MutableConfiguration<Long, String> extraSetup(MutableConfiguration<Long, String> configuration) {
  return configuration.setStoreByValue(true);
}