Spring 数据 GemFire:CustomExpiry 示例
Spring Data GemFire: CustomExpiry Examples
我正在使用 Pivotal GemFire 9.1.1 和 Spring Data GemFire 2.0。7.RELEASE。
我有一个将存储在 GemFire 区域中的令牌,该区域具有 String
键和 Map<String,String>
值。令牌的到期时间(即进入 GemFire 区域)应该是动态的,具体取决于一些业务场景。
我可以找到 CustomExpiry
的 Pivotal GemFire 文档,而我在 Spring Data GemFire (<gfe:custom-entry-ttl>
) 上找不到任何合适的 example/documentation。
如果有指示如何在 Spring Data GemFire 中启用自定义数据过期的资源,请分享。
开发人员实际上可以通过 3 种不同的方式使用 SDG
中的 Pivotal GemFire 的 o.a.g.cache.CustomExpiry
界面为区域配置自定义过期策略
鉴于 o.a.g.cacheCustomExpiry
...
的应用程序特定实现
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) {
...
}
}
首先,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>
正如您在上面的示例中所看到的,您可以使用 bean 引用来定义 "custom" 过期策略,如嵌套的生存时间 (TTL) 过期策略声明或使用匿名bean 定义,如 "Example" 分区区域 bean 定义的嵌套空闲超时 (TTI) 过期策略。
请参阅 SDG XML schema 以获得准确的定义。
其次,你可以实现同样的事情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;
}
}
最后,您使用基于 SDG 注释的过期配置来配置 TTL 和 TTI 过期策略,正如演示此功能的 SDG 测试套件中定义的here. There is a test class along with the configuration。
有关 SDG 中基于注释的过期配置的其他信息,请参见 here。
希望对您有所帮助!
-约翰
我正在使用 Pivotal GemFire 9.1.1 和 Spring Data GemFire 2.0。7.RELEASE。
我有一个将存储在 GemFire 区域中的令牌,该区域具有 String
键和 Map<String,String>
值。令牌的到期时间(即进入 GemFire 区域)应该是动态的,具体取决于一些业务场景。
我可以找到 CustomExpiry
的 Pivotal GemFire 文档,而我在 Spring Data GemFire (<gfe:custom-entry-ttl>
) 上找不到任何合适的 example/documentation。
如果有指示如何在 Spring Data GemFire 中启用自定义数据过期的资源,请分享。
开发人员实际上可以通过 3 种不同的方式使用 SDG
中的 Pivotal GemFire 的o.a.g.cache.CustomExpiry
界面为区域配置自定义过期策略
鉴于 o.a.g.cacheCustomExpiry
...
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) {
...
}
}
首先,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>
正如您在上面的示例中所看到的,您可以使用 bean 引用来定义 "custom" 过期策略,如嵌套的生存时间 (TTL) 过期策略声明或使用匿名bean 定义,如 "Example" 分区区域 bean 定义的嵌套空闲超时 (TTI) 过期策略。
请参阅 SDG XML schema 以获得准确的定义。
其次,你可以实现同样的事情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;
}
}
最后,您使用基于 SDG 注释的过期配置来配置 TTL 和 TTI 过期策略,正如演示此功能的 SDG 测试套件中定义的here. There is a test class along with the configuration。
有关 SDG 中基于注释的过期配置的其他信息,请参见 here。
希望对您有所帮助!
-约翰