[英]Spring Data GemFire: CustomExpiry Examples
I am using Pivotal GemFire 9.1.1 and Spring Data GemFire 2.0.7.RELEASE. 我正在使用Pivotal GemFire 9.1.1和Spring Data GemFire 2.0.7.RELEASE。
I have a token that will be stored in a GemFire Region with a String
Key and a Map<String,String>
Value. 我有一个令牌,该令牌将通过
String
键和Map<String,String>
值存储在GemFire区域中。 The expiration of the token (ie entry in the GemFire Region) should be dynamic dependent on a few business scenarios. 令牌的到期时间(即GemFire区域中的条目)应该是动态的,具体取决于一些业务场景。
I could find Pivotal GemFire documentation for CustomExpiry
whereas I could not find any proper example/documentation on Spring Data GemFire ( <gfe:custom-entry-ttl>
). 我可以找到
CustomExpiry
Pivotal GemFire文档,而在Spring Data GemFire( <gfe:custom-entry-ttl>
)上找不到任何适当的示例/文档。
Please share if there is a resource which instructs how to enable custom data expiration in Spring Data GemFire. 如果有资源指示如何在Spring Data GemFire中启用自定义数据过期,请分享。
There are actually 3 different ways a developer can configure a custom expiration policy for a Region using Pivotal GemFire's oagcache.CustomExpiry
interface in SDG 实际上,开发人员可以使用Pivotal GemFire的
oagcache.CustomExpiry
为SDG配置区域的自定义过期策略的3种不同方式oagcache.CustomExpiry
中的oagcache.CustomExpiry
接口
Given an application-specific implementation of oagcacheCustomExpiry
... 给定特定于应用程序的
oagcacheCustomExpiry
实现...
package example.app.gemfire.cache;
import org.apache.geode.cache.CustomExpiry;
import org.apache.geode.cache.ExpirationAttributes;
import ...;
class MyCustomExpiry implements CustomExpiry<String, Object> {
ExpirationAttributes getExpiry(Region.Entry<String, Object> entry) {
...
}
}
First, the XML approach. 首先,XML方法。
<bean id="customTimeToLiveExpiration"
class="example.app.gemfire.cache.MyCustomExpiry"/>
<gfe:partitioned-region id="Example" persistent="false">
<gfe:custom-entry-ttl ref="customTimeToLiveExpiration"/>
<gfe:custom-entry-tti>
<bean class="example.app.gemfire.cache.MyCustomExpiry"/>
</gfe:custom-entry-tti>
</gfe:partitioned-region>
As you can see in the example above, you can define "custom" Expiration policies using either a bean reference, as in the nested Time-To-Live (TTL) Expiration Policy declaration or by using a anonymous bean definition, as in the nested Idle Timeout (TTI) Expiration Policy of the "Example" PARTITION Region bean definition. 如您在上面的示例中看到的,您可以使用bean引用(如嵌套的生存时间(TTL)过期策略声明)或使用匿名bean定义(如嵌套)来定义“自定义”过期策略“示例” PARTITION Region Bean定义的空闲超时(TTI)过期策略。
Refer to the SDG XML schema for precise definitions. 有关精确定义,请参考SDG XML模式 。
Second, you can achieve the same thing Java Config... 其次,您可以实现相同的Java配置...
@Configuration
class GemFireConfiguration {
@Bean
MyCustomExpiry customTimeToLiveExpiration() {
return new MyCustomExpiry();
}
@Bean("Example")
PartitionedRegionFactoryBean<String, Object> exampleRegion(
GemFireCache gemfireCache) {
PartitionedRegionFactoryBean<String, Object> exampleRegion =
new PartitionedRegionFactoryBean<>();
exampleRegion.setCache(gemfireCache);
exampleRegion.setClose(false);
exampleRegion.setPersistent(false);
exampleRegion.setCustomEntryTimeToLive(customTimeToLiveExpiration());
exampleRegion.setCustomEntryIdleTimeout(new MyCustomExpiry());
return exampleRegion;
}
}
Finally, you configure both TTL and TTI Expiration Policies using SDG Annotation-based Expiration configuration, as defined here . 最后,同时配置了TTL,并使用基于注解的SDG过期的配置,定义TTI过期策略在这里 。 There is a test class along with the configuration in the SDG test suite demonstrating this capability.
SDG测试套件中有一个测试类以及配置 ,证明了此功能。
Additional information about Annotation-based Expiration configuration in SDG can be found here . 可以在此处找到有关SDG中基于注释的过期配置的其他信息。
Hope this helps! 希望这可以帮助!
-John -约翰
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.