Search code examples
javacachingconcurrencyoracle-coherence

Coherence EntryProcessor query


I'm trying to implement a business functionality which uses Coherence transient caches.

One of the features I was planning to depend upon is auto-eviction of cache entries, when providing a (configurable) time-to-live at the time of putting an item in the cache. The interface NamedCache provides an API to achieve this (http://download.oracle.com/otn_hosted_doc/coherence/330/com/tangosol/net/NamedCache.html#put(java.lang.Object, java.lang.Object, long)).

However, I'm also planning to use Entry-Processors to ensure effective concurrency across the cluster. I'm stuck at a point now where, within the scope of the processor, I'm supposed to work with InvocableMap.Entry to get/set values with a key in the cache. Unfortunately, there is no setValue method which lets me specify the time-to-live value.

I'm assuming here that interfacing directly with the NamedCache reference inside the EntryProcessor's process method will not be a good idea, and will compromise the concurrency guarantees which EntryProcessor provides.

Can you please share your thoughts on what could be the best way to get an entry evicted after a certain amount of time (which is dynamically decided), while ensuring optimal concurrency across a cluster of nodes?

I'm not completely hung up on using the auto-eviction functionality. However, if I were to abandon that, I may have to rely upon a timer-based programmatic removal of the entry, which works reliably across a cluster. Again, I'm falling short of ideas on this one. Ideally, I would want Coherence to deal with this.

Many thanks in advance.

Best regards, - Aditya


Solution

  • you can try the following: Cast the entry in the EntryProcessor to BinaryEntry and set the expiration time. For example:

    public class MyEntryProcessor extends AbstractProcessor  implements PortableObject {
    
     @Override
     public Object process(Entry myEntry) {     
    
        ((BinaryEntry)myEntry).expire(100);
        return myEntry;
     }
    }
    

    http://docs.oracle.com/middleware/1212/coherence/COHJR/com/tangosol/util/BinaryEntry.html