/** * Sets whether the element is eternal. * * @param eternal */ public void setEternal(final boolean eternal) { if (eternal) { this.cacheDefaultLifespan = false; this.timeToIdle = 0; this.timeToLive = 0; } else if (isEternal()) { this.cacheDefaultLifespan = false; this.timeToIdle = Integer.MIN_VALUE; this.timeToLive = Integer.MIN_VALUE; } }
/** * Set the default parameters of this element - those from its enclosing cache. * @param tti TTI in seconds * @param ttl TTL in seconds * @param eternal <code>true</code> if the element is eternal. */ protected void setLifespanDefaults(int tti, int ttl, boolean eternal) { if (eternal) { this.timeToIdle = 0; this.timeToLive = 0; } else if (isEternal()) { this.timeToIdle = Integer.MIN_VALUE; this.timeToLive = Integer.MIN_VALUE; } else { timeToIdle = tti; timeToLive = ttl; } }
@Override public ElementData createElementData(Element element) { if(element.isEternal()) { return new EternalElementData(element); } else { return new NonEternalElementData(element); } }
private boolean doPutWithCustomLifespan(String portableKey, Element element) { ElementData value = valueModeHandler.createElementData(element); int creationTimeInSecs = (int) (element.getCreationTime() / 1000); int customTTI = element.isEternal() ? Integer.MAX_VALUE : element.getTimeToIdle(); int customTTL = element.isEternal() ? Integer.MAX_VALUE : element.getTimeToLive(); if (checkContainsKeyOnPut) { return backend.put(portableKey, value, creationTimeInSecs, customTTI, customTTL) == null; } else { backend.putNoReturn(portableKey, value, creationTimeInSecs, customTTI, customTTL); return true; } }
/** * An element is expired if the expiration time as given by {@link #getExpirationTime()} is in the past. * * @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() { if (!isLifespanSet() || isEternal()) { return false; } long now = getCurrentTime(); long expirationTime = getExpirationTime(); return now > expirationTime; }
/** * 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; }
public boolean isEternal() { return element.isEternal(); }
public boolean isEternal() { return element.isEternal(); }
public boolean isEternal() { return element.isEternal(); }
public boolean isEternal() { return element.isEternal(); }
/** * Sets whether the element is eternal. * * @param eternal */ public void setEternal(final boolean eternal) { if (eternal) { this.cacheDefaultLifespan = false; this.timeToIdle = 0; this.timeToLive = 0; } else if (isEternal()) { this.cacheDefaultLifespan = false; this.timeToIdle = Integer.MIN_VALUE; this.timeToLive = Integer.MIN_VALUE; } }
/** * Sets whether the element is eternal. * * @param eternal */ public void setEternal(final boolean eternal) { if (eternal) { this.cacheDefaultLifespan = false; this.timeToIdle = 0; this.timeToLive = 0; } else if (isEternal()) { this.cacheDefaultLifespan = false; this.timeToIdle = Integer.MIN_VALUE; this.timeToLive = Integer.MIN_VALUE; } }
private boolean skipUpdateAccessStatistics(Element element) { if (configuration.isFrozen()) { boolean forLifetime = element.isEternal(); boolean forHeap = configuration.getMaxEntriesLocalHeap() > 0 || configuration.getMaxBytesLocalHeap() > 0 || getCacheManager().getConfiguration().isMaxBytesLocalHeapSet(); boolean forDisk = configuration.isOverflowToDisk() && (configuration.getMaxEntriesLocalDisk() > 0 || configuration.getMaxBytesLocalDisk() > 0 || getCacheManager().getConfiguration().isMaxBytesLocalDiskSet()); return !(forLifetime || forHeap || forDisk); } else { return false; } }
@Override public String getMetaData(Element element) { return String.valueOf(element.isEternal()); }},
/** * An element is expired if the expiration time as given by {@link #getExpirationTime()} is in the past. * * @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() { if (!isLifespanSet() || isEternal()) { return false; } long now = System.currentTimeMillis(); long expirationTime = getExpirationTime(); return now > expirationTime; }
/** * An element is expired if the expiration time as given by {@link #getExpirationTime()} is in the past. * * @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() { if (!isLifespanSet() || isEternal()) { return false; } long now = getCurrentTime(); long expirationTime = getExpirationTime(); return now > expirationTime; }
/** * An element is expired if the expiration time as given by {@link #getExpirationTime()} is in the past. * * @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() { if (!isLifespanSet() || isEternal()) { return false; } long now = getCurrentTime(); long expirationTime = getExpirationTime(); return now > expirationTime; }
private boolean skipUpdateAccessStatistics(Element element) { return configuration.isFrozen() && element.isEternal() && (configuration.getMaxElementsInMemory() == 0) && (!configuration.isOverflowToDisk() || configuration.getMaxElementsOnDisk() == 0); }
private boolean skipUpdateAccessStatistics(Element element) { if (configuration.isFrozen()) { boolean forLifetime = element.isEternal(); boolean forHeap = configuration.getMaxEntriesLocalHeap() > 0 || configuration.getMaxBytesLocalHeap() > 0 || getCacheManager().getConfiguration().isMaxBytesLocalHeapSet(); boolean forDisk = configuration.isOverflowToDisk() && (configuration.getMaxEntriesLocalDisk() > 0 || configuration.getMaxBytesLocalDisk() > 0 || getCacheManager().getConfiguration().isMaxBytesLocalDiskSet()); return !(forLifetime || forHeap || forDisk); } else { return false; } }
private boolean skipUpdateAccessStatistics(Element element) { if (configuration.isFrozen()) { boolean forLifetime = element.isEternal(); boolean forHeap = configuration.getMaxEntriesLocalHeap() > 0 || configuration.getMaxBytesLocalHeap() > 0 || getCacheManager().getConfiguration().isMaxBytesLocalHeapSet(); boolean forDisk = configuration.isOverflowToDisk() && (configuration.getMaxEntriesLocalDisk() > 0 || configuration.getMaxBytesLocalDisk() > 0 || getCacheManager().getConfiguration().isMaxBytesLocalDiskSet()); return !(forLifetime || forHeap || forDisk); } else { return false; } }