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


Java CreatedExpiryPolicy类代码示例

本文整理汇总了Java中javax.cache.expiry.CreatedExpiryPolicy的典型用法代码示例。如果您正苦于以下问题:Java CreatedExpiryPolicy类的具体用法?Java CreatedExpiryPolicy怎么用?Java CreatedExpiryPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: main

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {

		try (Ignite ignite = Ignition.start("config/default-config.xml")) {

			CacheConfiguration<String, LocalDateTime> cacheCfg = new CacheConfiguration<>("CacheQueriesScanQueryExample");
			cacheCfg.setCacheMode(CacheMode.PARTITIONED).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 3)));

			try (IgniteCache<String, LocalDateTime> igniteCache = ignite.getOrCreateCache(cacheCfg)) {

				LocalDateTime now = LocalDateTime.now();

				igniteCache.put("doctor", now);
				igniteCache.put("doctor who", now.plusHours(10L));
				igniteCache.put("doctor who", now.minusYears(1L));

				System.out.println("--------ScanQuery----------");
				try (QueryCursor<Entry<Object, Object>> query = igniteCache.query(new ScanQuery<>((k, v) -> v.equals(now)))) {
					for (Entry<Object, Object> entry : query) {
						System.out.println(entry.getKey() + ":" + entry.getValue());
					}
				}
			}
		}
	}
 
开发者ID:sdcuike,项目名称:Ignite-2015,代码行数:25,代码来源:CacheQueriesScanQueryExample.java

示例2: getConfiguration

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(CACHE_NAME);
    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 10)));

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
开发者ID:apache,项目名称:ignite,代码行数:17,代码来源:ScanQueryOffheapExpiryPolicySelfTest.java

示例3: run

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void run() {
    try {
        barrier.await();

        ExpiryPolicy plc1 = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expirationDuration));

        int keyStart = keysRangeGenerator.getAndIncrement() * cnt;

        for (int i = keyStart; i < keyStart + cnt; i++)
            cache.withExpiryPolicy(plc1).put("key" + i, 1);

        barrier.await();
    }
    catch (Exception e) {
        throw new IgniteException(e);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:19,代码来源:GridCacheTtlManagerNotificationTest.java

示例4: testEvict

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/**
 * @throws Exception If failed.
 */
public void testEvict() throws Exception {
    Ignite ignite1 = startGrid(1);

    IgniteCache<Object, Object> cache = ignite1.cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(
        new Duration(TimeUnit.MILLISECONDS, 100L)));

    // Putting entry.
    for (int i = 0; i < KEYS; i++)
        cache.put(i, i);

    // Wait when entry
    U.sleep(200);

    // Check that entry is evicted from cache, but local store does contain it.
    for (int i = 0; i < KEYS; i++) {
        cache.localEvict(Arrays.asList(i));

        assertNull(cache.localPeek(i));

        assertEquals(i, (int)LOCAL_STORE_1.load(i).get1());

        assertEquals(i, cache.get(i));
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:28,代码来源:GridCacheAbstractLocalStoreSelfTest.java

示例5: getConfiguration

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    CacheConfiguration<Integer, Integer> ccfg =
        new CacheConfiguration<Integer, Integer>()
            .setName("config")
            .setAtomicityMode(CacheAtomicityMode.ATOMIC)
            .setBackups(0) // No need for backup, just load from the store if needed
            .setCacheStoreFactory(new CacheStoreFactory())
            .setOnheapCacheEnabled(true)
            .setEvictionPolicy(new LruEvictionPolicy(100))
            .setNearConfiguration(new NearCacheConfiguration<Integer, Integer>()
            .setNearEvictionPolicy(new LruEvictionPolicy<Integer, Integer>()));

    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 1)))
        .setReadThrough(true)
        .setWriteThrough(false);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
开发者ID:apache,项目名称:ignite,代码行数:24,代码来源:GridCachePartitionEvictionDuringReadThroughSelfTest.java

示例6: getConfiguration

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<String, Long> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setReadFromBackup(true);
    ccfg.setCopyOnRead(false);
    ccfg.setName(THROTTLES_CACHE_NAME);

    Duration expiryDuration = new Duration(TimeUnit.MINUTES, 1);

    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(expiryDuration));
    ccfg.setReadThrough(false);
    ccfg.setWriteThrough(true);

    ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>(new TestCacheStore()));

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
开发者ID:apache,项目名称:ignite,代码行数:26,代码来源:IgniteCacheWriteBehindNoUpdateSelfTest.java

示例7: checkLoad

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/**
 * @param async If {@code true} uses asynchronous method.
 * @throws Exception If failed.
 */
private void checkLoad(boolean async) throws Exception {
    IgniteCache<String, Integer> cache = jcache(0)
       .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));

     List<Integer> keys = new ArrayList<>();

    keys.add(primaryKey(jcache(0)));
    keys.add(primaryKey(jcache(1)));
    keys.add(primaryKey(jcache(2)));

    if (async)
        cache.loadCacheAsync(null, keys.toArray(new Integer[3])).get();
    else
        cache.loadCache(null, keys.toArray(new Integer[3]));

    assertEquals(3, cache.size(CachePeekMode.PRIMARY));

    Thread.sleep(TIME_TO_LIVE + WAIT_TIME);

    assertEquals(0, cache.size());
}
 
开发者ID:apache,项目名称:ignite,代码行数:26,代码来源:IgniteCacheExpiryStoreLoadSelfTest.java

示例8: checkLocalLoad

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/**
 * @param async If {@code true} uses asynchronous method.
 * @throws Exception If failed.
 */
private void checkLocalLoad(boolean async) throws Exception {
    final IgniteCache<String, Integer> cache = jcache(0)
        .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));

    List<Integer> keys = primaryKeys(cache, 3);

    if (async)
        cache.localLoadCacheAsync(null, keys.toArray(new Integer[3])).get();
    else
        cache.localLoadCache(null, keys.toArray(new Integer[3]));

    assertEquals(3, cache.localSize());

    boolean res = GridTestUtils.waitForCondition(new PA() {
        @Override public boolean apply() {
            return cache.localSize() == 0;
        }
    }, TIME_TO_LIVE + WAIT_TIME);

    assertTrue(res);
}
 
开发者ID:apache,项目名称:ignite,代码行数:26,代码来源:IgniteCacheExpiryStoreLoadSelfTest.java

示例9: basicConfiguration

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
@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"));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:17,代码来源:EhCache107ConfigurationIntegrationDocTest.java

示例10: testExpiryConfiguration

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的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

示例11: produce

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的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

示例12: testCacheStatisticsRemoveAll

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
@Test
public void testCacheStatisticsRemoveAll() throws Exception {

  long _EXPIRY_MILLIS = 3;
  //cannot be zero or will not be added to the cache
  ExpiryPolicy policy = new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, _EXPIRY_MILLIS));
  expiryPolicyServer.setExpiryPolicy(policy);

  MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
  config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient)).setStatisticsEnabled(true);
  Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);

  for (int i = 0; i < 100; i++) {
    cache.put(i, i+100);
  }
  //should work with all implementations
  Thread.sleep(_EXPIRY_MILLIS);
  cache.removeAll();

  assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
  //Removals does not count expired entries
  assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CacheRemovals"));

}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:25,代码来源:CacheExpiryTest.java

示例13: testCacheStatisticsRemoveAllNoneExpired

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
@Test
public void testCacheStatisticsRemoveAllNoneExpired() throws Exception {

  ExpiryPolicy policy = new CreatedExpiryPolicy(Duration.ETERNAL);
  expiryPolicyServer.setExpiryPolicy(policy);

  MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
  config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient))
      .setStatisticsEnabled(true);
  Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);
  for (int i = 0; i < 100; i++) {
    cache.put(i, i+100);
  }
  cache.removeAll();
  assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
  assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CacheRemovals"));
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:18,代码来源:CacheExpiryTest.java

示例14: initializrCacheManagerCustomizer

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
@Bean
public JCacheManagerCustomizer initializrCacheManagerCustomizer() {
	return cm -> {
		cm.createCache("initializr", config().setExpiryPolicyFactory(
				CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES)));
		cm.createCache("dependency-metadata", config());
		cm.createCache("project-resources", config());
	};
}
 
开发者ID:rvillars,项目名称:edoras-one-initializr,代码行数:10,代码来源:InitializrAutoConfiguration.java

示例15: init

import javax.cache.expiry.CreatedExpiryPolicy; //导入依赖的package包/类
/**
 * Init.
 */
@PostConstruct
public void init() {
    logger.info("Setting up Ignite Ticket Registry...");

    configureSecureTransport();

    if (logger.isDebugEnabled()) {
        logger.debug("igniteConfiguration.cacheConfiguration={}", igniteConfiguration.getCacheConfiguration());
        logger.debug("igniteConfiguration.getDiscoverySpi={}", igniteConfiguration.getDiscoverySpi());
        logger.debug("igniteConfiguration.getSslContextFactory={}", igniteConfiguration.getSslContextFactory());
        logger.debug("Ticket-granting ticket timeout: [{}s]", this.ticketGrantingTicketTimeoutInSeconds);
        logger.debug("Service ticket timeout: [{}s]", this.serviceTicketTimeoutInSeconds);
    }

    if (Ignition.state() == IgniteState.STOPPED) {
        ignite = Ignition.start(igniteConfiguration);
    } else if (Ignition.state() == IgniteState.STARTED) {
        ignite = Ignition.ignite();
    }

    serviceTicketsCache = ignite.getOrCreateCache(servicesCacheName);
    serviceTicketsCache.getConfiguration(CacheConfiguration.class)
        .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, serviceTicketTimeoutInSeconds)));

    ticketGrantingTicketsCache = ignite.getOrCreateCache(ticketsCacheName);
    ticketGrantingTicketsCache.getConfiguration(CacheConfiguration.class)
        .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, ticketGrantingTicketTimeoutInSeconds)));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:32,代码来源:IgniteTicketRegistry.java


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