xml 如何在 ignite 服务器中创建缓存过期策略?

How to create cache expiry policy in ignite server by xml?

这是我的例子-default.xml,

<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>

        <property name="CacheExpiryPolicy">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
           <property name="expiryPolicyFactory">
               <bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
                  <constructor-arg>
                      <bean class="javax.cache.expiry.Duration">
                          <constructor-arg value="MINUTES"/>
                          <constructor-arg value="5"/>
                      </bean>
                  </constructor-arg>
               </bean>
           </property>
        </bean>
        </property>

但上面给出的 Bean 属性 'CacheExpiryPolicy' 不可写或具有无效的 setter 方法。 setter 的参数类型是否匹配 getter 的 return 类型?

我该如何解决这个问题?

这是来自 documentation 的示例:

<property name="cacheConfiguration">
            <list>
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="cacheWithExpiryPolicy"/>
                    <property name="expiryPolicyFactory">
                        <bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
                            <constructor-arg>
                                <bean class="javax.cache.expiry.Duration">
                                    <constructor-arg value="MINUTES"/>
                                    <constructor-arg value="5"/>
                                </bean>
                            </constructor-arg>
                        </bean>
                    </property>
                </bean>
            </list>
</property>

我在 apache-ignite-users 论坛上发现了一个关于此的问题。

请参考这个here

因此,根据该论坛参考的最终更新 xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<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">

    <!-- Added cache expiry policy -->
    <bean id="cacheExpiryPolicy"
        class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
        <constructor-arg>
            <bean class="javax.cache.expiry.CreatedExpiryPolicy">
                <constructor-arg>
                    <bean class="javax.cache.expiry.Duration">
                        <constructor-arg value="MINUTES" />
                        <constructor-arg value="5" />
                    </bean>
                </constructor-arg>
            </bean>
        </constructor-arg>
    </bean>

    <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>

        <!-- set the cacheConfiguration property -->
        <property name="cacheConfiguration">
            <list>
                <bean
                    class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="default" />
                    <property name="atomicityMode" value="ATOMIC" />
                    <property name="expiryPolicyFactory">
                        <bean parent="cacheExpiryPolicy" />
                    </property>
                </bean>
            </list>
        </property>
    </bean>
</beans>