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