@Override public int weigh(K key, V value) { int weight = delegate.weigh(key, value); Caffeine.requireArgument(weight >= 0); return weight; }
@Override public int weigh(K key, V value) { return weigher.weigh(key, value); } }
@Override public int weigh(K key, CompletableFuture<V> future) { return isReady(future) ? delegate.weigh(key, future.join()) : 0; }
/** Configures the maximum weight and returns if set. */ private boolean configureMaximumWeight() { if (config.getMaximumWeight().isPresent()) { caffeine.maximumWeight(config.getMaximumWeight().getAsLong()); Weigher<K, V> weigher = config.getWeigherFactory().map(Factory::create) .orElseThrow(() -> new IllegalStateException("Weigher not configured")); caffeine.weigher((K key, Expirable<V> expirable) -> { return weigher.weigh(key, expirable.get()); }); } return config.getMaximumWeight().isPresent(); }
desc.expectThat("weight", node.getWeight(), is(weigher.weigh(key, value)));
requireNonNull(newValue); int weight = weigher.weigh(key, newValue); boolean[] replaced = new boolean[1]; @SuppressWarnings("unchecked")
V[] oldValue = (V[]) new Object[1]; long[] now = new long[1]; int weight = weigher.weigh(key, value); Node<K, V> node = data.computeIfPresent(nodeFactory.newLookupKey(key), (k, n) -> { synchronized (n) {
@Override public int weigh(K key, V value) { int weight = delegate.weigh(key, value); Caffeine.requireArgument(weight >= 0); return weight; }
@Override public int weigh(K key, CompletableFuture<V> future) { return isReady(future) ? delegate.weigh(key, future.join()) : 0; }
int newWeight = weigher.weigh(key, value); for (;;) { Node<K, V> prior = data.get(nodeFactory.newLookupKey(key));
public void inserted(CacheKey id, byte[] value) { int weigh = WEIGHER.weigh(id, value); size.addAndGet(weigh); } }
public @Override void onRemoval(CacheKey key, byte[] value, RemovalCause cause) { int weigh = WEIGHER.weigh(key, value); size.addAndGet(-weigh); }
V[] oldValue = (V[]) new Object[1]; long[] now = new long[1]; int weight = weigher.weigh(key, value); Node<K, V> node = data.computeIfPresent(nodeFactory.newLookupKey(key), (k, n) -> { synchronized (n) {
requireNonNull(newValue); int weight = weigher.weigh(key, newValue); boolean[] replaced = new boolean[1]; @SuppressWarnings("unchecked")
int newWeight = weigher.weigh(key, value); for (;;) { Node<K, V> prior = data.get(nodeFactory.newLookupKey(key));
/** Configures the maximum weight and returns if set. */ private boolean configureMaximumWeight() { if (config.getMaximumWeight().isPresent()) { caffeine.maximumWeight(config.getMaximumWeight().getAsLong()); Weigher<K, V> weigher = config.getWeigherFactory().map(Factory::create) .orElseThrow(() -> new IllegalStateException("Weigher not configured")); caffeine.weigher((K key, Expirable<V> expirable) -> { return weigher.weigh(key, expirable.get()); }); } return config.getMaximumWeight().isPresent(); }