/** * Take an entry (which may be null) and return that entry only if not expired. If expired, return a null. If the * entry is expired, it is NOT evicted from the map. This method is suitable for calling by methods that return an old * version of an entry being modified (put, replace, remove) - these methods should not return an old expired entry. * * @param entry A possibly null, possibly expired entry * @return A possibly null, never expired entry */ private TimestampedValue<V> filterExpired(final TimestampedValue<V> entry) { if (entry != null && entry.isExpired(getTime(), config)) { return null; } else { return entry; } }
private TimestampedValue<V> wrapValue(final V value) { if (value instanceof TimestampedValue) { // If application already supplies a TimestampedEntry, don't wrap it again initCapacityEvictionPolicyFromConfig((TimestampedValue) value); return (TimestampedValue<V>) value; } DefaultTimestampedValue<V> defaultTimestampedValue = new DefaultTimestampedValue<V>(value, getTime()); initCapacityEvictionPolicyFromConfig(defaultTimestampedValue); return defaultTimestampedValue; }
protected void invalidateCacheEntries(final Iterator<K> keys) { int examined = 0; int evicted = 0; while (keys.hasNext()) { K key = keys.next(); try { TimestampedValue<V> wrappedValue = data.get(key); if (wrappedValue == null) continue; examined++; int now = getTime(); if (wrappedValue.isExpired(now, config)) { evicted++; evict(key, wrappedValue, now); } } catch (Throwable t) { logger.error("Unhandled exception inspecting item for [" + key + "] for expiration", t); } } if (isStatisticsEnabled()) { statistics.increment(examined, evicted); } }
final int now = getTime();