0

我正在使用带有 ModifiedExpiryPolicy 的 Ignite 缓存,并且需要在事件执行之前执行一行代码。有什么帮助吗?

IgniteCache<String, Object> expiresCache = cache.withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(Time.MINUTES, timeInMins)));

public class ClassName {
public IgnitePredicate<CacheEvent> functionName() {
    return new IgnitePredicate<CacheEvent>() {  
        @Override
        public boolean apply(CacheEvent evt) {
            //code to be executed after event.
            return true;
            }
        };
    }
}
4

1 回答 1

1

我认为您需要使用事件来监听到期事件。

Ignite ignite = Ignition.ignite();

// Local listener that listenes to local events.
IgnitePredicate<CacheEvent> locLsnr = evt -> {
  System.out.println("Received expiry event [evt=" + evt.name() + ", key=" + evt.key());

  return true; // Continue listening.
};

// Subscribe to specified cache events occuring on local node.
ignite.events().localListen(locLsnr, EventType.EVT_CACHE_OBJECT_EXPIRED);

请注意,这只是一个本地(节点)侦听器,您需要一个远程侦听器来查找远程节点上的到期事件。您还需要includeEventTypes在配置文件中进行配置(出于性能原因,默认情况下禁用事件。

于 2019-07-19T14:51:25.247 回答