/** * Checks whether this cache element has expired. * <p> * The element is expired if: * <ol> * <li> the idle time is non-zero and has elapsed, unless the cache is eternal; or * <li> the time to live is non-zero and has elapsed, unless the cache is eternal; or * <li> the value of the element is null. * </ol> * * @return true if it has expired * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE} * @throws NullPointerException if the element is null * todo this does not need to be synchronized */ public final boolean isExpired(Element element) throws IllegalStateException, NullPointerException { checkStatus(); return element.isExpired(configuration); }
private Element nextExpiredOrToEvict(final Element justAdded) { Element lastUnpinned = null; int i = 0; while (i++ < count) { if (evictionIterator == null || !evictionIterator.hasNext()) { evictionIterator = iterator(); } final HashEntry next = evictionIterator.next(); if (!next.accessed || next.value.isExpired()) { return next.value; } else { if (next.value != justAdded) { lastUnpinned = next.value; } next.accessed = false; } } return lastUnpinned; }
private void notifyEvictionOrExpiry(final Element element) { if(element != null && cacheEventNotificationService != null) { if (element.isExpired()) { cacheEventNotificationService.notifyElementExpiry(element, false); } else { cacheEventNotificationService.notifyElementEvicted(element, false); } } }
/** * Evicts the element for the given key, if it exists and is expired * @param key the key * @return the evicted element, if any. Otherwise null */ protected Element expireElement(final Object key) { Element value = get(key); return value != null && value.isExpired() && map.remove(key, value) ? value : null; }
/** * Relies on being called from a synchronized method * * @param element * @return true if the LRU element should be removed */ private boolean removeLeastRecentlyUsedElement(Element element) throws CacheException { //check for expiry and remove before going to the trouble of spooling it if (element.isExpired()) { notifyExpiry(element); return true; } if (isFull() && !cachePinned) { evict(element); return true; } else { return false; } } }
if (diskSubstitute != null && element.isExpired()) { evict(key, hash, diskSubstitute);
/** * Removes the element chosen by the eviction policy * * @param elementJustAdded it is possible for this to be null * @return true if an element was removed, false otherwise. */ private boolean removeElementChosenByEvictionPolicy(final Element elementJustAdded) { if (policy == null) { return map.evict(); } Element element = findEvictionCandidate(elementJustAdded); if (element == null) { LOG.debug("Eviction selection miss. Selected element is null"); return false; } // If the element is expired, remove if (element.isExpired()) { remove(element.getObjectKey()); notifyExpiry(element); return true; } if (storePinned) { return false; } return evict(element); }
/** * 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(); }
writeLock().unlock(); if (notify && evictedElement != null) { if (evictedElement.isExpired()) { cacheEventNotificationService.notifyElementExpiry(evictedElement, false); } else {
class MyEvictionPolicy extends LruPolicy { // you can subclass FifoPolicy or LfuPolicy here @Override public Element selectedBasedOnPolicy(Element[] sampledElements, Element justAdded) { Element candidate = super.selectedBasedOnPolicy(sampledElements, justAdded); if (candidate.isExpired()) { // perform your action here } return candidate; } }
/** * {@inheritDoc} */ public void expireElements() { for (Object key : memory.getKeys()) { Sync s = sync.getSyncForKey(key); s.lock(LockType.WRITE); try { Element element = memory.getQuiet(key); if (element != null) { if (element.isExpired(config)) { Element e = remove(key); if (e != null) { eventListeners.notifyElementExpiry(e, false); } } } } finally { s.unlock(LockType.WRITE); } } //This is called regularly by the expiry thread, but call it here synchronously if (disk != null) { disk.expireElements(); } }
/** * Get an XKMSCacheToken from the cache matching the given key. Returns null if there * is no such XKMSCacheToken in the cache, or if the certificate has expired in the cache */ public XKMSCacheToken get(String key) { Element element = cache.get(key); if (element != null && !element.isExpired()) { return (XKMSCacheToken)element.getObjectValue(); } return null; }
@Override public ProfilerImpl load(UUID id) { Element profilerElement = cache.get(id); if (profilerElement == null || profilerElement.isExpired()) { return null; } return (ProfilerImpl) profilerElement.getObjectValue(); } }
/** * Get an XKMSCacheToken from the cache matching the given key. Returns null if there * is no such XKMSCacheToken in the cache, or if the certificate has expired in the cache */ public XKMSCacheToken get(String key) { Element element = cache.get(key); if (element != null && !element.isExpired()) { return (XKMSCacheToken)element.getObjectValue(); } return null; }
/** * Evicts the element for the given key, if it exists and is expired * @param key the key * @return the evicted element, if any. Otherwise null */ protected Element expireElement(final Object key) { Element value = get(key); return value != null && value.isExpired() && map.remove(key, value) ? value : null; }
private void notifyEvictionOrExpiry(final Element element) { if(element != null && cacheEventNotificationService != null) { if (element.isExpired()) { cacheEventNotificationService.notifyElementExpiry(element, false); } else { cacheEventNotificationService.notifyElementEvicted(element, false); } } }
/** * Evicts the element for the given key, if it exists and is expired * @param key the key * @return the evicted element, if any. Otherwise null */ protected Element expireElement(final Object key) { Element value = get(key); return value != null && value.isExpired() && map.remove(key, value) ? value : null; }
private void notifyEvictionOrExpiry(final Element element) { if(element != null && cacheEventNotificationService != null) { if (element.isExpired()) { cacheEventNotificationService.notifyElementExpiry(element, false); } else { cacheEventNotificationService.notifyElementEvicted(element, false); } } }
private void notifyEvictionOrExpiry(final Element element) { if(element != null && cacheEventNotificationService != null) { if (element.isExpired()) { cacheEventNotificationService.notifyElementExpiry(element, false); } else { cacheEventNotificationService.notifyElementEvicted(element, false); } } }
/** * Evicts the element for the given key, if it exists and is expired * @param key the key * @return the evicted element, if any. Otherwise null */ protected Element expireElement(final Object key) { Element value = get(key); return value != null && value.isExpired() && map.remove(key, value) ? value : null; }