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

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setExpiryPolicyFactory() . 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: ScanQueryOffheapExpiryPolicySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@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;
}
 
Example 3
Source File: IgnitePdsContinuousRestartTestWithExpiryPolicy.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName(CACHE_NAME);
    ccfg.setGroupName("Group1");
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 128));
    ccfg.setBackups(2);
    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 4
Source File: IgniteCacheNoSyncForGetTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param atomicityMode Atomicity mode.
 * @param heapCache Heap cache flag.
 * @param expiryPlc Expiry policy flag.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(CacheAtomicityMode atomicityMode,
    boolean heapCache,
    boolean expiryPlc) {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setOnheapCacheEnabled(heapCache);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setName("testCache");

    if (expiryPlc)
        ccfg.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(Duration.FIVE_MINUTES));

    return ccfg;
}
 
Example 5
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 6
Source File: IgniteCacheWriteBehindNoUpdateSelfTest.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<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;
}
 
Example 7
Source File: IgniteCache.java    From j2cache with Apache License 2.0 5 votes vote down vote up
public IgniteCache(String name, long maxSize, long maxLifetime) {
	this.name = name;
	this.maxCacheSize = maxSize;
	this.maxLifetime = maxLifetime;
	CacheConfiguration<K, V> config = new CacheConfiguration<K, V>();
	config.setName(name);
	config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, maxLifetime)));
    map = IgniteInstance.getInstance().getIgnite().getOrCreateCache(config);
}
 
Example 8
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 9
Source File: IgniteCacheExpiryPolicyWithStoreAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setExpiryPolicyFactory(new TestExpiryPolicyFactory());

    return ccfg;
}
 
Example 10
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 11
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 12
Source File: CacheConfig.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Configure streaming cache.
 */
public static CacheConfiguration<AffinityUuid, String> wordCache() {
    CacheConfiguration<AffinityUuid, String> cfg = new CacheConfiguration<>("words");

    // Index all words streamed into cache.
    cfg.setIndexedTypes(AffinityUuid.class, String.class);

    // Sliding window of 1 seconds.
    cfg.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(SECONDS, 1))));

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

    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);

    cfg.setFailureHandler(new StopNodeOrHaltFailureHandler());

    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setAtomicityMode(ATOMIC);
    ccfg.setCacheMode(PARTITIONED);
    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 14
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 15
Source File: IgniteCacheReadThroughEvictionSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception if failed.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-11849")
@Test
public void testReadThroughExpirePolicyConfigured() throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.EXPIRATION);

    Ignite ig = testedGrid();

    CacheConfiguration<Object, Object> cc = variationConfig("expireConfig");

    cc.setExpiryPolicyFactory(new ExpirePolicyFactory());

    IgniteCache<Object, Object> cache = ig.createCache(cc);

    try {
        for (int i = 0; i < KEYS; i++)
            cache.put(key(i), value(i));

        U.sleep(TIMEOUT);

        waitEmpty(cc.getName());

        for (int i = 0; i < KEYS; i++) {
            assertEquals(value(i), cache.get(key(i)));

            // Access expiry.
            cache.get(key(i));
        }

        U.sleep(TIMEOUT);

        waitEmpty(cc.getName());

        for (int i = 0; i < KEYS; i++)
            assertEquals(value(i), cache.get(key(i)));

        for (int i = 0; i < KEYS; i++) {
            assertEquals(value(i), cache.get(key(i)));

            // Update expiry.
            cache.put(key(i), value(i));
        }

        U.sleep(TIMEOUT);

        waitEmpty(cc.getName());

        for (int i = 0; i < KEYS; i++)
            assertEquals(value(i), cache.get(key(i)));
    }
    finally {
        destroyCacheSafe(ig, cc.getName());
    }
}
 
Example 16
Source File: CacheConfig.java    From tutorials with MIT License 3 votes vote down vote up
public static CacheConfiguration<Integer, Employee> employeeCache() {

        CacheConfiguration<Integer, Employee> config = new CacheConfiguration<>("baeldungEmployees");

        config.setIndexedTypes(Integer.class, Employee.class);
        config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(
                new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5))));

        return config;
    }