示例#1
0
 /**
  * An element is expired if the expiration time as given by {@link #getExpirationTime()} is in the
  * past.
  *
  * <p>This method in addition propogates the default TTI/TTL values of the supplied cache into
  * this element.
  *
  * @param config config to take default parameters from
  * @return true if the Element is expired, otherwise false. If no lifespan has been set for the
  *     Element it is considered not able to expire.
  * @see #getExpirationTime()
  */
 public boolean isExpired(CacheConfiguration config) {
   if (cacheDefaultLifespan) {
     if (config.isEternal()) {
       timeToIdle = 0;
       timeToLive = 0;
     } else {
       timeToIdle = TimeUtil.convertTimeToInt(config.getTimeToIdleSeconds());
       timeToLive = TimeUtil.convertTimeToInt(config.getTimeToLiveSeconds());
     }
   }
   return isExpired();
 }
示例#2
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;
  }
示例#3
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());
 }
示例#4
0
 /** Custom serialization write logic */
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.defaultWriteObject();
   out.writeInt(TimeUtil.toSecs(creationTime));
   out.writeInt(TimeUtil.toSecs(lastAccessTime));
 }