private V putNewEntry(final K key, final V value) { final int position = strategy.getStorePosition(); final MyWeakReference<K, V> reference = new MyWeakReference<K, V>(key, value, queue); final CacheSlot<K, V> old = accessMap.put(key, new CacheSlot<K, V>(position, reference)); if (old != null && old.reference != null) old.reference.clearKey(); if (cache[position] != null) { processReferenceQueue(); } cache[position] = Pair.create(key, value); strategy.registerAccess(position); return value; }
private V putEntryInSlot( final K key, final V value, final @NotNull CacheSlot<K, V> slot, final boolean alterCacheStrategy) { if (slot.reference != null) slot.reference.clearKey(); slot.reference = new MyWeakReference<K, V>(key, value, queue); cache[slot.position] = Pair.create(key, value); if (alterCacheStrategy) { strategy.registerAccess(slot.position); } return value; }
private boolean alterCacheStrategy(final K key, final Pair<K, V> atPosition) { return atPosition != null && (atPosition.getFirst() == key || atPosition.getFirst().equals(key)); }