public V replace(final K key, final V value) { return getValueSafe(filterExpired(this.data.replace(key, wrapValue(value)))); }
private TimestampedValue<V> getNonExpiredEntryUnsafe(K key, boolean markUsed) { return getNonExpiredEntry(key, markUsed, GetType.UNSAFE); }
public V get(final Object key) { return getValueSafe(getNonExpiredEntryCoherent((K) key, true)); }
public V unlockedGet(final K key) { return getValueSafe(getNonExpiredEntryUnlocked(key, true)); }
public V unsafeGet(final K key, final boolean quiet) { return getValueSafe(getNonExpiredEntryUnsafe(key, !quiet)); }
if (isEvictionEnabled() || isCapacityEvictionEnabled()) { final int now = getTime(); String lockId = getLockIdForKey(key); if (entry.isExpired(now, config)) { if (!ManagerUtil.isLockHeldByCurrentThread(lockId, Manager.LOCK_TYPE_READ)) { evict(key, entry, now);
public void evictOrphanElements(final DsoCluster clusterInfo) { if (isEvictionEnabled() && getConfig().isOrphanEvictionEnabled()) { for (Map m : data.getConstituentMaps()) { Set<K> keys = clusterInfo.getKeysForOrphanedValues(m); invalidateCacheEntries(keys.iterator()); } } }
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); } }
public StoreImpl(CacheConfig config) { config = (config instanceof ImmutableConfig) ? config : new ImmutableConfig(config); this.data = new DistributedCacheImpl<String, V>(config); }
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; }
public V remove(final Object key) { return getValueSafe(filterExpired(this.data.remove(key))); }
private void initCapacityEvictionPolicyFromConfig(final TimestampedValue timestampedValue) { if (isCapacityEvictionEnabled()) { // use CapacityEvictionPolicyData.Factory in config to create a new one if its not an instance of the config's // factory CapacityEvictionPolicyData current = timestampedValue.getCapacityEvictionPolicyData(); if (!getConfig().getCapacityEvictionPolicyDataFactory().isProductOfFactory(current)) { CapacityEvictionPolicyData cep = getConfig().getCapacityEvictionPolicyDataFactory() .newCapacityEvictionPolicyData(); timestampedValue.setCapacityEvictionPolicyData(cep); } } }
protected void initializeOnLoad(final boolean startEviction) { if (config.isLoggingEnabled()) { logger.info("Initializing CHMDistributedMap, starting eviction thread"); } this.timeSource = new SystemTimeSource(); this.orphanEvictor = new OrphanEvictionListener<K>(config, this, orphanEvictorLock); this.evictionScheduler = new EvictionScheduler(config, new Evictor<K>(this, orphanEvictor)); this.statistics = new EvictionStatistics(); this.data.registerMapSizeListener(new TargetCapacityMapSizeListener(data, getConfig())); if (startEviction) { startEviction(); } }
public boolean unlockedContainsKey(final Object key) { TimestampedValue<V> entry = getNonExpiredEntryUnlocked((K) key, false); return entry != null; }
public boolean containsKey(final Object key) { TimestampedValue<V> entry = getNonExpiredEntryCoherent((K) key, false); return entry != null; }
public TimestampedValue<V> unsafeGetTimestampedValue(final K key, final boolean quiet) { return getNonExpiredEntryUnsafe(key, !quiet); }
public TimestampedValue<V> removeTimestampedValue(final K key) { return filterExpired(this.data.remove(key)); }
/** * 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; } }
public <K, V> DistributedCache<K, V> newCache() { MutableConfig copyConfig = new MutableConfig(name, loggingEnabled, maxTTISeconds, maxTTLSeconds, orphanEvictionEnabled, orphanEvictionPeriod, targetMaxInMemoryCount, targetMaxTotalCount, capacityEvictionPolicyDataFactory); if (CacheConfigFactory.DSO_ACTIVE) { return new DistributedCacheImpl<K, V>(copyConfig); } else { return new LocalCache<K, V>(copyConfig); } }
public TimestampedValue unlockedGetTimestampedValueQuiet(final K key) { return getNonExpiredEntryUnlocked(key, false); }