本文整理汇总了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());
}
}
}
}
}
示例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;
}
示例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);
}
}
示例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));
}
}
示例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;
}
示例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;
}
示例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());
}
示例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);
}
示例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"));
}
示例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));
}
示例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;
}
示例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"));
}
示例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"));
}
示例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());
};
}
示例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)));
}