How to set expiry time for all Ignite caches?

[亡魂溺海] 提交于 2021-01-29 13:08:26

问题


I am starting ignite by a specific configuration. In that configuration, I specified expiration policy. But expiration is not working. When I specified a cache name in that property, it is working fine.

I added configuration like below

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

But this is not working for all caches,

When I tried config like below it is working,

<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="SECONDS"/>
                            <constructor-arg value="5"/>
                          </bean>
                        </constructor-arg>
                      </bean>
                    </property>
                    <property name="name" value="test"/>
                    <property name="atomicityMode" value="ATOMIC"/>
                    <property name="backups" value="1"/>
                </bean>

Here the cache "test" is expiring correctly.


回答1:


You can declare an abstract CacheConfiguration bean containing <expiryPolicyFactory>, and inherit (using parent="beanName") all of cache cfg's from that bean. That's how it usually done in Spring:

<bean id="expireCache" class="org.apache.ignite.configuration.CacheConfiguration" abstract="true">
    <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 name="cacheConfiguration">
        <list>
            <bean parent="expireCache">
                <property name="name" value="test"/>
                <property name="atomicityMode" value="ATOMIC"/>
                <property name="backups" value="1"/>
            </bean>
...

Abstract bean should be put on the top level alongside with IgniteConfiguration bean.



来源:https://stackoverflow.com/questions/57703010/how-to-set-expiry-time-for-all-ignite-caches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!