Example #1
0
  /**
   * Returns the expiration time based on time to live. If this element also has a time to idle
   * setting, the expiry time will vary depending on whether the element is accessed.
   *
   * @return the time to expiration
   */
  public long getExpirationTime() {
    if (!isLifespanSet() || isEternal()) {
      return Long.MAX_VALUE;
    }

    long expirationTime = 0;
    long ttlExpiry = creationTime + TimeUtil.toMillis(getTimeToLive());

    long mostRecentTime = Math.max(creationTime, lastAccessTime);
    long ttiExpiry = mostRecentTime + TimeUtil.toMillis(getTimeToIdle());

    if (getTimeToLive() != 0 && (getTimeToIdle() == 0 || lastAccessTime == 0)) {
      expirationTime = ttlExpiry;
    } else if (getTimeToLive() == 0) {
      expirationTime = ttiExpiry;
    } else {
      expirationTime = Math.min(ttlExpiry, ttiExpiry);
    }
    return expirationTime;
  }
Example #2
0
 /** Custom serialization read logic */
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   in.defaultReadObject();
   creationTime = TimeUtil.toMillis(in.readInt());
   lastAccessTime = TimeUtil.toMillis(in.readInt());
 }