如何设置所有Ignite缓存的到期时间? [英] How to set expiry time for all Ignite caches?
问题描述
我正在通过特定配置开始点火.在该配置中,我指定了过期策略.但是过期是行不通的.当我在该属性中指定缓存名称时,它可以正常工作.
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.
我添加了如下配置
<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,
当我尝试如下配置时,
<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.
推荐答案
您可以声明一个包含< expiryPolicyFactory>
的抽象
CacheConfiguration bean,并继承(使用 parent ="beanName"
)来自该bean的所有缓存cfg.在春季通常是这样的:
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>
...
抽象Bean应该与IgniteConfiguration Bean一起放在顶层.
Abstract bean should be put on the top level alongside with IgniteConfiguration bean.
这篇关于如何设置所有Ignite缓存的到期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!