3

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.

Abhijeet Behare
  • 597
  • 1
  • 7
  • 21

2 Answers2

2

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); 
      }
    }
});
Dan Smith
  • 481
  • 2
  • 3
1

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.