Hi,
You can use a Stream Receiver(visitor implementation) to intercept
incoming entries and create an expiry policy on the fly.
see:https://apacheignite.readme.io/docs/data-streamers#streamvisitor
example:
CacheConfiguration cfg = new CacheConfiguration("wordCache");
IgniteCache<String, String> wordCache =
ignite.getOrCreateCache(cfg);
try (IgniteDataStreamer<String, String> stmr =
ignite.dataStreamer(wordCache.getName())) {
// Allow data updates.
stmr.allowOverwrite(true);
// Configure data transformation to count instances of the same
word.
stmr.receiver(StreamVisitor.from((cache, e) -> {
String key = e.getKey();
String val = e.getValue();
System.out.println("reciever: " + key + " : " + val);
cache.withExpiryPolicy( new CreatedExpiryPolicy( new
Duration(TimeUnit.SECONDS, 5))).put(key, val);
cache.put(key+"1", val+"1");
}));
String[] text = new String[] {"a", "b", "c"};
// Stream words into the streamer cache.
for (String word : text)
stmr.addData(word, word);
}
String[] text = new String[] {"a", "b", "c"};
// Stream words into the streamer cache.
for (String word : text)
System.out.println("before expire word: " +
wordCache.get(word));
//wait for some entries to expire
Thread.sleep(10 * 1000L);
//these entries will be expired
for (String word : text)
System.out.println("expired word: " + wordCache.get(word));
//these will not be expired
for (String word : text)
System.out.println("non expired word: " +
wordCache.get(word+"1"));
Thanks, Alex
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/