当前位置: 首页>>代码示例>>Java>>正文


Java MutableConfiguration.setExpiryPolicyFactory方法代码示例

本文整理汇总了Java中javax.cache.configuration.MutableConfiguration.setExpiryPolicyFactory方法的典型用法代码示例。如果您正苦于以下问题:Java MutableConfiguration.setExpiryPolicyFactory方法的具体用法?Java MutableConfiguration.setExpiryPolicyFactory怎么用?Java MutableConfiguration.setExpiryPolicyFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.cache.configuration.MutableConfiguration的用法示例。


在下文中一共展示了MutableConfiguration.setExpiryPolicyFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateCacheWithModifiedExpiryPolicy

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testCreateCacheWithModifiedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY));

    Cache cache = cacheManager.createCache("cache", configuration);

    CompleteConfiguration actualConfiguration =
        (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);

    assertEquals(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY), actualConfiguration.getExpiryPolicyFactory());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:18,代码来源:GuavaCacheManagerTest.java

示例2: testCreateCacheWithTouchedExpiryPolicy

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testCreateCacheWithTouchedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));

    Cache cache = cacheManager.createCache("cache", configuration);

    CompleteConfiguration actualConfiguration =
        (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);

    assertEquals(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE), actualConfiguration.getExpiryPolicyFactory());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:18,代码来源:GuavaCacheManagerTest.java

示例3: getOrCreateCacheConfiguration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
Configuration getOrCreateCacheConfiguration() {
    if (configuration.getCacheConfiguration() != null) {
        return configuration.getCacheConfiguration();
    }

    MutableConfiguration mutableConfiguration = new MutableConfiguration();
    if (configuration.getCacheLoaderFactory() != null) {
        mutableConfiguration.setCacheLoaderFactory(configuration.getCacheLoaderFactory());
    }
    if (configuration.getCacheWriterFactory() != null) {
        mutableConfiguration.setCacheWriterFactory(configuration.getCacheWriterFactory());
    }
    if (configuration.getExpiryPolicyFactory() != null) {
        mutableConfiguration.setExpiryPolicyFactory(configuration.getExpiryPolicyFactory());
    }

    mutableConfiguration.setManagementEnabled(configuration.isManagementEnabled());
    mutableConfiguration.setStatisticsEnabled(configuration.isStatisticsEnabled());
    mutableConfiguration.setReadThrough(configuration.isReadThrough());
    mutableConfiguration.setStoreByValue(configuration.isStoreByValue());

    return mutableConfiguration;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:JCacheManager.java

示例4: testExpiryConfiguration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testExpiryConfiguration() {
  final AtomicBoolean expiryCreated = new AtomicBoolean(false);

  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class);
  configuration.setExpiryPolicyFactory(() -> {
    expiryCreated.set(true);
    return new CreatedExpiryPolicy(Duration.FIVE_MINUTES);
  });

  Cache<String, String> cache = cacheManager.createCache("cache", configuration);

  cache.putIfAbsent("42", "The Answer");
  cache.putIfAbsent("42", "Or not!?");

  assertThat(expiryCreated.get(), is(true));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:19,代码来源:SimpleEh107ConfigTest.java

示例5: createConfiguration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Override public <K, V> CompleteConfiguration<K, V> createConfiguration( Class<K> keyType, Class<V> valueType,
                                                                         Map<String, String> properties ) {
  MutableConfiguration<K, V> configuration = new MutableConfiguration<K, V>();
  configuration.setTypes( keyType, valueType );

  if ( properties.containsKey( CONFIG_TTL ) ) {
    Long ttl = Longs.tryParse( Strings.nullToEmpty( properties.get( CONFIG_TTL ) ) );
    Preconditions.checkArgument( ttl != null, "Template config error", CONFIG_TTL );

    Optional<ExpiryFunction> expiryFunction;
    if ( properties.containsKey( CONFIG_TTL_RESET ) ) {
      expiryFunction = Enums.getIfPresent( ExpiryFunction.class, properties.get( CONFIG_TTL_RESET ) );
    } else {
      expiryFunction = Optional.of( CONFIG_TTL_RESET_DEFAULT );
    }
    Preconditions.checkArgument( expiryFunction.isPresent(), "Template config error", CONFIG_TTL_RESET );

    configuration.setExpiryPolicyFactory( expiryFunction.get().createFactory( ttl ) );
  }
  if ( properties.containsKey( CONFIG_STORE_BY_VALUE ) ) {
    configuration.setStoreByValue( Boolean.valueOf( properties.get( CONFIG_STORE_BY_VALUE ) ) );
  }
  return configuration;
}
 
开发者ID:pentaho,项目名称:pentaho-osgi-bundles,代码行数:25,代码来源:AbstractCacheProvidingService.java

示例6: produce

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Produces
@LimitedCache
public Cache<Integer, Person> produce() {
	CacheManager manager = Caching.getCachingProvider().getCacheManager();

	Cache<Integer, Person> cache = manager.getCache(CACHE_NAME, Integer.class, Person.class);
	if(cache == null) {
		MutableConfiguration<Integer, Person> configuration = new MutableConfiguration<>();
		configuration.setTypes(Integer.class, Person.class);
		configuration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));

		cache = manager.createCache(CACHE_NAME, configuration);

		CacheEntryListenerConfiguration<Integer, Person> listenersConfiguration = new MutableCacheEntryListenerConfiguration<>(
				FactoryBuilder.factoryOf(CacheModificationListener.class), null, false, true);
		cache.registerCacheEntryListener(listenersConfiguration);
	}

	return cache;
}
 
开发者ID:wesleyegberto,项目名称:javaee_projects,代码行数:21,代码来源:LimitedCacheExposer.java

示例7: testExpiryOnCreation

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testExpiryOnCreation() throws Exception {

    // close cache since need to configure cache with ExpireOnCreationPolicy
    CacheManager mgr = cache.getCacheManager();
    mgr.destroyCache(cache.getName());

    MutableConfiguration<Long, String> config = new MutableConfiguration<Long, String>();
    config.setStatisticsEnabled(true);
    config.setTypes(Long.class, String.class);
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(ExpireOnCreationPolicy.class));

    cache = mgr.createCache(getTestCacheName(), config);
    cache.put(1L, "hello");
    assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));

    Map<Long, String> map = new HashMap<Long, String>();
    map.put(2L, "goodbye");
    map.put(3L, "world");
    cache.putAll(map);
    assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:23,代码来源:CacheMBStatisticsBeanTest.java

示例8: createCacheConfiguration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:CachingPrincipalAttributesRepository.java

示例9: testExpiration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@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();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:35,代码来源:JCacheTest.java

示例10: JCacheStore

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
public JCacheStore(Factory<ExpiryPolicy> expiryPolicyFactory) {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<String, Serializable> config = new MutableConfiguration<String, Serializable>()
            .setTypes(String.class, Serializable.class);
    if (expiryPolicyFactory != null) {
        config.setExpiryPolicyFactory(expiryPolicyFactory);
    }
    cache = cacheManager.getCache("session", String.class, Serializable.class);
    if (cache == null)
        cache = cacheManager.createCache("session", config);
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:14,代码来源:JCacheStore.java

示例11: testCreateCacheWithUnsupportedAccessedExpiryPolicy

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test(expected = UnsupportedOperationException.class)
public void testCreateCacheWithUnsupportedAccessedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ZERO));

    cacheManager.createCache("cache", configuration);
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:13,代码来源:GuavaCacheManagerTest.java

示例12: testCreateCacheWithUnsupportedCreatedExpiryPolicy

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test(expected = UnsupportedOperationException.class)
public void testCreateCacheWithUnsupportedCreatedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ZERO));

    cacheManager.createCache("cache", configuration);
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:13,代码来源:GuavaCacheManagerTest.java

示例13: myCustomizer

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Bean
JCacheManagerCustomizer myCustomizer() {
	return new JCacheManagerCustomizer() {
		@Override
		public void customize(javax.cache.CacheManager cacheManager) {
			MutableConfiguration<?, ?> config = new MutableConfiguration<Object, Object>();
			config.setExpiryPolicyFactory(
					CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
			config.setStatisticsEnabled(true);
			cacheManager.createCache("custom1", config);
			cacheManager.destroyCache("bar");
		}
	};
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:CacheAutoConfigurationTests.java

示例14: containsKeyShouldNotCallExpiryPolicyMethods

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void containsKeyShouldNotCallExpiryPolicyMethods() {

    CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();

    MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicy));
    Cache<Integer, Integer> cache = getCacheManager().createCache("test", config);

    cache.containsKey(1);

    assertThat(expiryPolicy.getCreationCount(), is(0));
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));

    cache.put(1, 1);

    assertTrue(expiryPolicy.getCreationCount() >= 1);
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));
    expiryPolicy.resetCount();

    cache.containsKey(1);

    assertThat(expiryPolicy.getCreationCount(), is(0));
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));
}
 
开发者ID:diennea,项目名称:blazingcache,代码行数:29,代码来源:TCKCacheManagerTest.java

示例15: invokeSetValueShouldCallGetExpiry

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void invokeSetValueShouldCallGetExpiry() {

    CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();

    MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicy));
    Cache<Integer, Integer> cache = getCacheManager().createCache("test-4", config);

    final Integer key = 123;
    final Integer setValue = 456;
    final Integer modifySetValue = 789;

    // verify create
    EntryProcessor processors[]
            = new EntryProcessor[]{
                new AssertNotPresentEntryProcessor(null),
                new SetEntryProcessor<Integer, Integer>(setValue),
                new GetEntryProcessor<Integer, Integer>()
            };
    Object[] result = (Object[]) cache.invoke(key, new CombineEntryProcessor(processors));

    assertEquals(result[1], setValue);
    assertEquals(result[2], setValue);

    // expiry called should be for create, not for the get or modify.
    // Operations get combined in entry processor and only net result should be expiryPolicy method called.
    assertTrue(expiryPolicy.getCreationCount() >= 1);
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));
    expiryPolicy.resetCount();

    // verify modify
    Integer resultValue = cache.invoke(key, new SetEntryProcessor<Integer, Integer>(modifySetValue));
    assertEquals(modifySetValue, resultValue);

    assertThat(expiryPolicy.getCreationCount(), is(0));
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertTrue(expiryPolicy.getUpdatedCount() >= 1);
}
 
开发者ID:diennea,项目名称:blazingcache,代码行数:41,代码来源:TCKCacheManagerTest.java


注:本文中的javax.cache.configuration.MutableConfiguration.setExpiryPolicyFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。