protected TimingsHolder<K, V> findTimingsHolder(long ttl) { WeakReference<TimingsHolder<K, V>> ref = timings.get(ttl); TimingsHolder<K, V> timingsHolder; while (true) { if (ref == null) { timingsHolder = new TimingsHolder<K, V>(ttl); WeakReference<TimingsHolder<K, V>> existed = timings.putIfAbsent(ttl, ref = new WeakReference<TimingsHolder<K, V>>(timingsHolder)); if (existed == null) return timingsHolder; TimingsHolder<K, V> th = existed.get(); if (th != null) return th; if (timings.replace(ttl, existed, ref)) return timingsHolder; ref = timings.get(ttl); } else { timingsHolder = ref.get(); if (timingsHolder != null) return timingsHolder; ref = null; } } }
protected TimingsHolder<K, V> findTimingsHolder(long ttl) { WeakReference<TimingsHolder<K, V>> ref = timings.get(ttl); TimingsHolder<K, V> timingsHolder; while (true) { if (ref == null) { timingsHolder = new TimingsHolder<K, V>(ttl); WeakReference<TimingsHolder<K, V>> existed = timings.putIfAbsent(ttl, ref = new WeakReference<TimingsHolder<K, V>>(timingsHolder)); if (existed == null) return timingsHolder; TimingsHolder<K, V> th = existed.get(); if (th != null) return th; if (timings.replace(ttl, existed, ref)) return timingsHolder; ref = timings.get(ttl); } else { timingsHolder = ref.get(); if (timingsHolder != null) return timingsHolder; ref = null; } } }
public Cache(String name, long ttlSec, Computable<? super K, ? extends V> computable) { this.name = name != null ? name : "Cache-" + NAME_COUNTER.incrementAndGet(); this.ttl = ttlSec * 1000; this.computable = computable; statistics = createStatistics(); timings.put(ttl, new WeakReference<TimingsHolder<K, V>>(timingsHolder = new TimingsHolder<K, V>(ttl))); CacheCleaner.addCache(this); }
public Cache(String name, long ttlSec, Computable<? super K, ? extends V> computable) { this.name = name != null ? name : "Cache-" + NAME_COUNTER.incrementAndGet(); this.ttl = ttlSec * 1000; this.computable = computable; statistics = createStatistics(); timings.put(ttl, new WeakReference<TimingsHolder<K, V>>(timingsHolder = new TimingsHolder<K, V>(ttl))); CacheCleaner.addCache(this); }