Reputation: 607
Hi I am new to gemfire and i want to exprire data from gemfire region for specific key after idle time which I set.
i did this using redis by below code.
jedis.set(key, value);
config.setMaxIdle(50);
jedis.expire(key, config.getMaxIdle());
but how to do it in gemfire.
Any help.
Thanks.
Upvotes: 3
Views: 380
Reputation: 158
If you want to delete data for specific region then try following code :
Region<String, String> region = cache .<String, String> createClientRegionFactory( ClientRegionShortcut.CACHING_PROXY) .setEntryTimeToLive(new ExpirationAttributes(50)) .create(PropertiesCache.getInstance().getProperty("region"));
It's works in my situation.
Upvotes: 1
Reputation: 491
You can control the expiration of individual keys if you configure the region to use a custom expiration. You provide an implementation of the CustomExpiry interface that can look at each entry and decide when it should expire. For example:
RegionFactory regionFactory = ...
regionFactory.setCustomEntryIdleTimeout(new CustomExpiry() {
public ExpirationAttributes getExpiry(Entry entry) {
if(entry.getKey().equals("XXX")) {
return new ExpirationAttributes(50, ExpirationAction.INVALIDATE);
}
}
});
Upvotes: 2