2 Replies Latest reply: Oct 12, 2012 8:06 AM by 967979 RSS

    Object expiration time

    967979
      Hi
      I have little question about object expiration time in Coherence. I have specific issue - some objects (in the same type) contains field with date which specified expiration time of it (or time in seconds). Can I configure time of life per object in Coherence cache?
        • 1. Re: Object expiration time
          Jonathan.Knight
          Hi,

          There are a couple of ways of doing this.

          1. Specify the expiry time when you put the object into the cache.
          cache.put(key, value, expiryTime);
          2. Write a trigger on the cache that sets the expiry time on the entry when the cache is updated. This will then work regardless of how values are added or updated. Triggers are explained here: http://docs.oracle.com/cd/E24290_01/coh.371/e22837/api_triggers.htm#CIHCAIBE
          public class ExpirySettingTrigger implements MapTrigger, PortableObject {
          
              @Override
              public void process(Entry entry) {
                  long expiry = // get the expiry from the value being added/updated - entry.getValue() 
                  ((BinaryEntry)entry).expire(expiry);
              }
          
              @Override
              public void readExternal(PofReader pofReader) throws IOException {
              }
          
              @Override
              public void writeExternal(PofWriter pofWriter) throws IOException {
              }
          }
          JK
          • 2. Re: Object expiration time
            967979
            Is works for me. Thank you very much.