boolean usesAccessQueue() { return expiresAfterAccess() || evictsBySize(); }
boolean usesAccessQueue() { return expiresAfterAccess() || evictsBySize(); }
boolean usesAccessQueue() { return expiresAfterAccess() || evictsBySize(); }
AbstractCacheSet(ConcurrentMap<?, ?> map) { this.map = map; }
static <K, V> void checkAndDrainRecencyQueue( LocalCache<K, V> map, Segment<K, V> segment, List<ReferenceEntry<K, V>> reads) { if (map.evictsBySize() || map.expiresAfterAccess()) { assertSameEntries(reads, ImmutableList.copyOf(segment.recencyQueue)); } segment.drainRecencyQueue(); }
static <K, V> void checkEvictionQueues( LocalCache<K, V> map, Segment<K, V> segment, List<ReferenceEntry<K, V>> readOrder, List<ReferenceEntry<K, V>> writeOrder) { if (map.evictsBySize() || map.expiresAfterAccess()) { assertSameEntries(readOrder, ImmutableList.copyOf(segment.accessQueue)); } if (map.expiresAfterWrite()) { assertSameEntries(writeOrder, ImmutableList.copyOf(segment.writeQueue)); } }
/** * Performs eviction if the segment is over capacity. Avoids flushing the entire cache if the * newest entry exceeds the maximum weight all on its own. * * @param newest the most recently added entry */ @GuardedBy("this") void evictEntries(ReferenceEntry<K, V> newest) { if (!map.evictsBySize()) { return; } drainRecencyQueue(); // If the newest entry by itself is too heavy for the segment, don't bother evicting // anything else, just that if (newest.getValueReference().getWeight() > maxSegmentWeight) { if (!removeEntry(newest, newest.getHash(), RemovalCause.SIZE)) { throw new AssertionError(); } } while (totalWeight > maxSegmentWeight) { ReferenceEntry<K, V> e = getNextEvictable(); if (!removeEntry(e, e.getHash(), RemovalCause.SIZE)) { throw new AssertionError(); } } }
/** * Performs eviction if the segment is over capacity. Avoids flushing the entire cache if the * newest entry exceeds the maximum weight all on its own. * * @param newest the most recently added entry */ @GuardedBy("this") void evictEntries(ReferenceEntry<K, V> newest) { if (!map.evictsBySize()) { return; } drainRecencyQueue(); // If the newest entry by itself is too heavy for the segment, don't bother evicting // anything else, just that if (newest.getValueReference().getWeight() > maxSegmentWeight) { if (!removeEntry(newest, newest.getHash(), RemovalCause.SIZE)) { throw new AssertionError(); } } while (totalWeight > maxSegmentWeight) { ReferenceEntry<K, V> e = getNextEvictable(); if (!removeEntry(e, e.getHash(), RemovalCause.SIZE)) { throw new AssertionError(); } } }
AbstractCacheSet(ConcurrentMap<?, ?> map) { this.map = map; }
AbstractCacheSet(ConcurrentMap<?, ?> map) { this.map = map; }
static void checkEviction(LocalCache<?, ?> map) { if (map.evictsBySize()) { for (Segment<?, ?> segment : map.segments) { drainRecencyQueue(segment); assertEquals(0, segment.recencyQueue.size()); assertEquals(0, segment.readCount.get()); ReferenceEntry<?, ?> prev = null; for (ReferenceEntry<?, ?> current : segment.accessQueue) { if (prev != null) { assertSame(prev, current.getPreviousInAccessQueue()); assertSame(prev.getNextInAccessQueue(), current); } Object key = current.getKey(); if (key != null) { assertSame(current, segment.getEntry(key, current.getHash())); } prev = current; } } } else { for (Segment<?, ?> segment : map.segments) { assertEquals(0, segment.recencyQueue.size()); } } }
/** * Performs eviction if the segment is over capacity. Avoids flushing the entire cache if the * newest entry exceeds the maximum weight all on its own. * * @param newest the most recently added entry */ @GuardedBy("this") void evictEntries(ReferenceEntry<K, V> newest) { if (!map.evictsBySize()) { return; } drainRecencyQueue(); // If the newest entry by itself is too heavy for the segment, don't bother evicting // anything else, just that if (newest.getValueReference().getWeight() > maxSegmentWeight) { if (!removeEntry(newest, newest.getHash(), RemovalCause.SIZE)) { throw new AssertionError(); } } while (totalWeight > maxSegmentWeight) { ReferenceEntry<K, V> e = getNextEvictable(); if (!removeEntry(e, e.getHash(), RemovalCause.SIZE)) { throw new AssertionError(); } } }
public void testDefaults() { LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder()); assertSame(Strength.STRONG, map.keyStrength); assertSame(Strength.STRONG, map.valueStrength); assertSame(map.keyStrength.defaultEquivalence(), map.keyEquivalence); assertSame(map.valueStrength.defaultEquivalence(), map.valueEquivalence); assertEquals(0, map.expireAfterAccessNanos); assertEquals(0, map.expireAfterWriteNanos); assertEquals(0, map.refreshNanos); assertEquals(CacheBuilder.UNSET_INT, map.maxWeight); assertSame(EntryFactory.STRONG, map.entryFactory); assertSame(CacheBuilder.NullListener.INSTANCE, map.removalListener); assertSame(DISCARDING_QUEUE, map.removalNotificationQueue); assertSame(NULL_TICKER, map.ticker); assertEquals(4, map.concurrencyLevel); // concurrency level assertThat(map.segments).hasLength(4); // initial capacity / concurrency level assertEquals(16 / map.segments.length, map.segments[0].table.length()); assertFalse(map.evictsBySize()); assertFalse(map.expires()); assertFalse(map.expiresAfterWrite()); assertFalse(map.expiresAfterAccess()); assertFalse(map.refreshes()); }
boolean usesAccessQueue() { return expiresAfterAccess() || evictsBySize(); }
boolean usesAccessQueue() { return expiresAfterAccess() || evictsBySize(); }
boolean usesAccessQueue() { return expiresAfterAccess() || evictsBySize(); }
AbstractCacheSet(ConcurrentMap<?, ?> map) { this.map = map; }
AbstractCacheSet(ConcurrentMap<?, ?> map) { this.map = map; }
static <K, V> void checkAndDrainRecencyQueue(LocalCache<K, V> map, Segment<K, V> segment, List<ReferenceEntry<K, V>> reads) { if (map.evictsBySize() || map.expiresAfterAccess()) { assertSameEntries(reads, ImmutableList.copyOf(segment.recencyQueue)); } segment.drainRecencyQueue(); }
static <K, V> void checkEvictionQueues(LocalCache<K, V> map, Segment<K, V> segment, List<ReferenceEntry<K, V>> readOrder, List<ReferenceEntry<K, V>> writeOrder) { if (map.evictsBySize() || map.expiresAfterAccess()) { assertSameEntries(readOrder, ImmutableList.copyOf(segment.accessQueue)); } if (map.expiresAfterWrite()) { assertSameEntries(writeOrder, ImmutableList.copyOf(segment.writeQueue)); } }