Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setEagerTtl()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setEagerTtl() . 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: CacheTtlReadOnlyModeSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
private static CacheConfiguration[] getCacheConfigurations() {
    CacheConfiguration[] cfgs = cacheConfigurations();

    List<CacheConfiguration> newCfgs = new ArrayList<>(cfgs.length);

    for (CacheConfiguration cfg : cfgs) {
        if (cfg.getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) {
            // Expiry policy cannot be used with TRANSACTIONAL_SNAPSHOT.
            continue;
        }

        cfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(SECONDS, EXPIRATION_TIMEOUT)));
        cfg.setEagerTtl(true);

        newCfgs.add(cfg);
    }

    return newCfgs.toArray(new CacheConfiguration[0]);
}
 
Example 2
Source File: GridCacheUtils.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Create system cache used by Hadoop component.
 *
 * @return Hadoop cache configuration.
 */
public static CacheConfiguration hadoopSystemCache() {
    CacheConfiguration cache = new CacheConfiguration();

    cache.setName(CU.SYS_CACHE_HADOOP_MR);
    cache.setCacheMode(REPLICATED);
    cache.setAtomicityMode(TRANSACTIONAL);
    cache.setWriteSynchronizationMode(FULL_SYNC);

    cache.setEvictionPolicyFactory(null);
    cache.setEvictionPolicy(null);
    cache.setCacheStoreFactory(null);
    cache.setNodeFilter(CacheConfiguration.ALL_NODES);
    cache.setEagerTtl(true);
    cache.setRebalanceMode(SYNC);

    return cache;
}
 
Example 3
Source File: GridCacheTtlManagerEvictionSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(cacheMode);
    ccfg.setEagerTtl(true);
    ccfg.setEvictionPolicy(new FifoEvictionPolicy(ENTRIES_LIMIT, 100));
    ccfg.setOnheapCacheEnabled(true);
    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 4
Source File: CacheQueryFilterExpiredTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ignite Node.
 * @param atomicityMode Cache atomicity mode.
 * @param eagerTtl Value for {@link CacheConfiguration#setEagerTtl(boolean)}.
 * @throws Exception If failed.
 */
private void checkFilterExpired(Ignite ignite, CacheAtomicityMode atomicityMode, boolean eagerTtl) throws Exception {
    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setEagerTtl(eagerTtl);
    ccfg.setIndexedTypes(Integer.class, Integer.class);

    final IgniteCache<Integer, Integer> cache = ignite.createCache(ccfg);

    try {
        IgniteCache<Integer, Integer> expCache =
            cache.withExpiryPolicy(new TouchedExpiryPolicy(new Duration(0, 2000)));

        for (int i = 0; i < 10; i++) {
            IgniteCache<Integer, Integer> cache0 = i % 2 == 0 ? cache : expCache;

            cache0.put(i, i);
        }

        assertEquals(10, cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size());
        assertEquals(10, cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size());

        GridTestUtils.waitForCondition(new GridAbsPredicate() {
            @Override public boolean apply() {
                return cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size() == 5 &&
                    cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size() == 5;
            }
        }, 5000);

        assertEquals(5, cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size());
        assertEquals(5, cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size());
    }
    finally {
        ignite.destroyCache(ccfg.getName());
    }
}
 
Example 5
Source File: GridCacheTtlManagerNotificationTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration createCacheConfiguration(String name) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(cacheMode);
    ccfg.setEagerTtl(true);
    ccfg.setName(name);

    return ccfg;
}
 
Example 6
Source File: IgniteCacheOnlyOneTtlCleanupThreadExistsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @param eagerTtl Eager ttl falg.
 * @return Cache configuration.
 */
private CacheConfiguration createCacheConfiguration(@NotNull String name, boolean eagerTtl) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setEagerTtl(eagerTtl);
    ccfg.setName(name);

    return ccfg;
}
 
Example 7
Source File: IgniteCacheExpiryPolicyAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration cfg = super.cacheConfiguration(igniteInstanceName);

    if (nearCache)
        cfg.setNearConfiguration(new NearCacheConfiguration());

    cfg.setExpiryPolicyFactory(factory);

    if (disableEagerTtl)
        cfg.setEagerTtl(false);

    return cfg;
}
 
Example 8
Source File: IgnitePdsWithTtlDeactivateOnHighloadTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new cache configuration with the given name and {@code GROUP_NAME} group.
 *
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration<?, ?> getCacheConfiguration(String name) {
    CacheConfiguration<?, ?> ccfg = new CacheConfiguration<>();

    ccfg.setName(name);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, PART_SIZE));
    ccfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, EXPIRATION_TIMEOUT)));
    ccfg.setEagerTtl(true);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);

    return ccfg;
}
 
Example 9
Source File: IgnitePdsWithTtlTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new cache configuration with the given name and {@code GROUP_NAME} group.
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration getCacheConfiguration(String name) {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName(name);
    ccfg.setGroupName(GROUP_NAME);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, PART_SIZE));
    ccfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, EXPIRATION_TIMEOUT)));
    ccfg.setEagerTtl(true);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);

    return ccfg;
}
 
Example 10
Source File: IgniteCacheEntryListenerAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_EVENTS);

    CacheConfiguration cfg = super.cacheConfiguration(igniteInstanceName);

    if (lsnrCfg != null)
        cfg.addCacheEntryListenerConfiguration(lsnrCfg);

    cfg.setEagerTtl(eagerTtl());

    return cfg;
}
 
Example 11
Source File: IgnitePdsWithTtlTest2.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
public CacheConfiguration getCacheConfiguration(String name) {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName(name);

    ccfg.setAtomicityMode(ATOMIC);

    ccfg.setBackups(1);

    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32768));

    ccfg.setEagerTtl(true);

    ccfg.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 20)));

    return ccfg;
}
 
Example 12
Source File: GridCacheTtlManagerSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.EXPIRATION);

    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(cacheMode);
    ccfg.setEagerTtl(true);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}