There are actually 3 different ways a developer can configure a custom expiration policy for a Region using Pivotal GemFire's o.a.g.cache.CustomExpiry
interface in SDG
Given an application-specific implementation of 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) {
...
}
}
First, the XML approach.
<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.
Refer to the SDG XML schema for precise definitions.
Second, you can achieve the same thing Java Config...
@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. There is a test class along with the configuration in the SDG test suite demonstrating this capability.
Additional information about Annotation-based Expiration configuration in SDG can be found here.
Hope this helps!
-John