setAccessTime(node, now); afterRead(node, now, /* recordHit */ false);
@Test(dataProvider = "caches") @CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine, population = Population.EMPTY, maximumSize = Maximum.FULL) public void exceedsMaximumBufferSize_onRead(Cache<Integer, Integer> cache, CacheContext context) { BoundedLocalCache<Integer, Integer> localCache = asBoundedLocalCache(cache); Node<Integer, Integer> dummy = localCache.nodeFactory.newNode( new WeakKeyReference<>(null, null), null, null, 1, 0); localCache.frequencySketch().ensureCapacity(1); Buffer<Node<Integer, Integer>> buffer = localCache.readBuffer; for (int i = 0; i < BoundedBuffer.BUFFER_SIZE; i++) { buffer.offer(dummy); } assertThat(buffer.offer(dummy), is(Buffer.FULL)); localCache.afterRead(dummy, 0, /* recordHit */ true); assertThat(buffer.offer(dummy), is(not(Buffer.FULL))); }
@Override public @Nullable V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, boolean recordStats, boolean recordLoad) { requireNonNull(key); requireNonNull(mappingFunction); long now = expirationTicker().read(); // An optimistic fast path to avoid unnecessary locking Node<K, V> node = data.get(nodeFactory.newLookupKey(key)); if (node != null) { V value = node.getValue(); if ((value != null) && !hasExpired(node, now)) { if (!isComputingAsync(node)) { setVariableTime(node, expireAfterRead(node, key, value, expiry(), now)); setAccessTime(node, now); } afterRead(node, now, /* recordHit */ true); return value; } } if (recordStats) { mappingFunction = statsAware(mappingFunction, recordLoad); } Object keyRef = nodeFactory.newReferenceKey(key, keyReferenceQueue()); return doComputeIfAbsent(key, keyRef, mappingFunction, new long[] { now }); }
@Override public @Nullable V getIfPresent(Object key, boolean recordStats) { Node<K, V> node = data.get(nodeFactory.newLookupKey(key)); if (node == null) { if (recordStats) { statsCounter().recordMisses(1); } return null; } V value = node.getValue(); long now = expirationTicker().read(); if (hasExpired(node, now) || (collectValues() && (value == null))) { if (recordStats) { statsCounter().recordMisses(1); } scheduleDrainBuffers(); return null; } if (!isComputingAsync(node)) { @SuppressWarnings("unchecked") K castedKey = (K) key; setAccessTime(node, now); setVariableTime(node, expireAfterRead(node, castedKey, value, expiry(), now)); } afterRead(node, now, recordStats); return value; }
afterWrite(new UpdateTask(node, weightedDifference)); } else { afterRead(node, now[0], /* recordHit */ false);
afterWrite(new UpdateTask(node, weightedDifference)); } else { afterRead(node, now[0], /* recordHit */ false);
setWriteTime(prior, now); afterRead(prior, now, /* recordHit */ false);
afterRead(node, now[0], /* recordHit */ true); return oldValue[0];
scheduleDrainBuffers(); afterRead(node, now[0], /* recordHit */ false);
setAccessTime(node, now); afterRead(node, now, /* recordHit */ false);
@Override public @Nullable V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, boolean recordStats, boolean recordLoad) { requireNonNull(key); requireNonNull(mappingFunction); long now = expirationTicker().read(); // An optimistic fast path to avoid unnecessary locking Node<K, V> node = data.get(nodeFactory.newLookupKey(key)); if (node != null) { V value = node.getValue(); if ((value != null) && !hasExpired(node, now)) { if (!isComputingAsync(node)) { setVariableTime(node, expireAfterRead(node, key, value, expiry(), now)); setAccessTime(node, now); } afterRead(node, now, /* recordHit */ true); return value; } } if (recordStats) { mappingFunction = statsAware(mappingFunction, recordLoad); } Object keyRef = nodeFactory.newReferenceKey(key, keyReferenceQueue()); return doComputeIfAbsent(key, keyRef, mappingFunction, new long[] { now }); }
@Override public @Nullable V getIfPresent(Object key, boolean recordStats) { Node<K, V> node = data.get(nodeFactory.newLookupKey(key)); if (node == null) { if (recordStats) { statsCounter().recordMisses(1); } return null; } long now = expirationTicker().read(); if (hasExpired(node, now)) { if (recordStats) { statsCounter().recordMisses(1); } scheduleDrainBuffers(); return null; } @SuppressWarnings("unchecked") K castedKey = (K) key; V value = node.getValue(); if (!isComputingAsync(node)) { setVariableTime(node, expireAfterRead(node, castedKey, value, expiry(), now)); setAccessTime(node, now); } afterRead(node, now, recordStats); return value; }
afterWrite(new UpdateTask(node, weightedDifference)); } else { afterRead(node, now[0], /* recordHit */ false);
afterWrite(new UpdateTask(node, weightedDifference)); } else { afterRead(node, now[0], /* recordHit */ false);
setWriteTime(prior, now); afterRead(prior, now, /* recordHit */ false);
afterRead(node, now[0], /* recordHit */ true); return oldValue[0];
scheduleDrainBuffers(); afterRead(node, now[0], /* recordHit */ false);