Sky
Sky

Reputation: 2607

How to set expiry policy for ignite Cache [Inserting data using SPARK Dataframe]

I am trying to set Expiry Policy using xml config file:

<?xml version="1.0" encoding="UTF-8"?>
 <!--
  Ignite configuration with all defaults and enabled p2p deployment and enabled events.
 -->
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util.xsd">
<bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <!-- Set to true to enable distributed class loading for examples, default is false. -->
    <property name="peerClassLoadingEnabled" value="true"/>

    <!-- Enable task execution events for examples. -->
    <property name="includeEventTypes">
        <list>
            <!--Task execution events-->
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/>

            <!--Cache events-->
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
        </list>
    </property>

    <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
    <property name="discoverySpi">
        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
            <property name="ipFinder">
                <!--
                    Ignite provides several options for automatic discovery that can be used
                    instead os static IP based discovery. For information on all options refer
                    to our documentation: http://apacheignite.readme.io/docs/cluster-config
                -->
                <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
                <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
                <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                    <property name="addresses">
                        <list>
                            <!-- In distributed environment, replace with actual host IP address. -->
                            <value>127.0.0.1:47500..47509</value>
                        </list>
                    </property>
                </bean>
            </property>
        </bean>
    </property>
</bean>
<bean class="org.apache.ignite.configuration.CacheConfiguration">

    <property name="setExpiryPolicyFactory" >
        <bean class="javax.cache.expiry.CreatedExpiryPolicy">
              <!---- Remove all data after 10 Seconds---->
            <property name="expiryDuration" value="10000"/>
        </bean>
    </property>
    <property name="eagerTtl" value="true"/>
</bean>

I am a bit new for Ignite. I walk through documentation but unable to find. Is any way to setExpiryPolicy into XMl?

Any help would be appreciated!

Upvotes: 1

Views: 1842

Answers (2)

ggdio
ggdio

Reputation: 180

Apache Ignite doesn`t support expiry policies and TTL for SQL tables.

An alternative would be to create cache with dynamically generated names based on desired time window.

For example you could append hour of the day if you need it hourly:

MY_CACHE_00

MY_CACHE_01

MY_CACHE_02

etc...

MY_CACHE_23

Then make your software write/read to the latest hour CACHE, and clear the oldest.

Upvotes: 1

Stanislav Lukyanov
Stanislav Lukyanov

Reputation: 2157

That requires a bit of Spring XML magic because there is no easy-to-use factory class for the CreatedExpiryPolicy (i.e. no CreatedExpiryPolicyFactory that you can just instantiate like a normal bean), but there is the CreatedExpiryPolicy::factoryOf that can be passed as factory-method:

<property name="expiryPolicyFactory">
    <bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
        <constructor-arg>
            <bean class="javax.cache.expiry.Duration">
                <constructor-arg value="SECONDS"/>
                <constructor-arg value="10"/>
            </bean>
        </constructor-arg>
    </bean>
</property>

Upvotes: 2

Related Questions