Skip to content

Commit

Permalink
fix minor warnings (grammar, code, test stabilization)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Feb 27, 2024
1 parent 94d7c8a commit e872e2e
Show file tree
Hide file tree
Showing 29 changed files with 58 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Powering infrastructure near you:

* An in-depth description of Caffeine's architecture.
* [Design of a Modern Cache: part #1][modern-cache-1], [part #2][modern-cache-2]
([slides][modern-cache-slides]) at [HighScalability][HighScalability]
([slides][modern-cache-slides]) at [HighScalability][]
* Caffeine is presented as part of research papers evaluating its novel eviction policy.
* [TinyLFU: A Highly Efficient Cache Admission Policy][tinylfu]
by Gil Einziger, Roy Friedman, Ben Manes
Expand Down Expand Up @@ -136,7 +136,7 @@ Snapshots of the development version are available in
[modern-cache-1]: http://highscalability.com/blog/2016/1/25/design-of-a-modern-cache.html
[modern-cache-2]: http://highscalability.com/blog/2019/2/25/design-of-a-modern-cachepart-deux.html
[modern-cache-slides]: https://docs.google.com/presentation/d/1NlDxyXsUG1qlVHMl4vsUUBQfAJ2c2NsFPNPr2qymIBs
[highscalability]: http://highscalability.com
[HighScalability]: http://highscalability.com
[spring]: https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#cache-store-configuration-caffeine
[scala-cache]: https://github.com/cb372/scalacache
[scaffeine]: https://github.com/blemale/scaffeine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ CompletableFuture<V> get(K key, BiFunction<? super K, ? super Executor,
/**
* Returns the future of a map of the values associated with the {@code keys}, creating or
* retrieving those values if necessary. The returned map contains entries that were already
* cached, combined with newly loaded entries; it will never contain null keys or values. If the
* any of the asynchronous computations fail, those entries will be automatically removed from
* this cache.
* cached, combined with newly loaded entries; it will never contain null keys or values. If any
* of the asynchronous computations fail, those entries will be automatically removed from this
* cache.
* <p>
* A single request to the {@code mappingFunction} is performed for all keys which are not already
* present in the cache. If another call to {@link #get} tries to load the value for a key in
Expand All @@ -128,10 +128,10 @@ CompletableFuture<Map<K, V>> getAll(Iterable<? extends K> keys,
/**
* Returns the future of a map of the values associated with the {@code keys}, creating or
* retrieving those values if necessary. The returned map contains entries that were already
* cached, combined with newly loaded entries; it will never contain null keys or values. If the
* any of the asynchronous computations fail, those entries will be automatically removed from
* this cache. The instances returned from the {@code mappingFunction} will be stored directly
* into the cache.
* cached, combined with newly loaded entries; it will never contain null keys or values. If any
* of the asynchronous computations fail, those entries will be automatically removed from this
* cache. The instances returned from the {@code mappingFunction} will be stored directly into the
* cache.
* <p>
* A single request to the {@code mappingFunction} is performed for all keys which are not already
* present in the cache. If another call to {@link #get} tries to load the value for a key in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3864,7 +3864,7 @@ static final class PerformCleanupTask extends ForkJoinTask<Void> implements Runn
final WeakReference<BoundedLocalCache<?, ?>> reference;

PerformCleanupTask(BoundedLocalCache<?, ?> cache) {
reference = new WeakReference<BoundedLocalCache<?,?>>(cache);
reference = new WeakReference<>(cache);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ default CompletableFuture<? extends V> asyncReload(
static <K, V> CacheLoader<K, V> bulk(Function<? super Set<? extends K>,
? extends Map<? extends K, ? extends V>> mappingFunction) {
requireNonNull(mappingFunction);
return new CacheLoader<K, V>() {
return new CacheLoader<>() {
@Override public @Nullable V load(K key) {
return loadAll(Set.of(key)).get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,8 @@ public <K1 extends K, V1 extends V> AsyncLoadingCache<K1, V1> buildAsync(
@SuppressWarnings("unchecked")
Caffeine<K1, V1> self = (Caffeine<K1, V1>) this;
return isBounded() || refreshAfterWrite()
? new BoundedLocalCache.BoundedLocalAsyncLoadingCache<K1, V1>(self, loader)
: new UnboundedLocalCache.UnboundedLocalAsyncLoadingCache<K1, V1>(self, loader);
? new BoundedLocalCache.BoundedLocalAsyncLoadingCache<>(self, loader)
: new UnboundedLocalCache.UnboundedLocalAsyncLoadingCache<>(self, loader);
}

void requireNonLoadingCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ final class Interned<K, V> extends Node<K, V> implements NodeFactory<K, V> {
return new LookupKeyEqualsReference<>(key);
}
@Override public Object newReferenceKey(K key, ReferenceQueue<K> referenceQueue) {
return new WeakKeyEqualsReference<K>(key, referenceQueue);
return new WeakKeyEqualsReference<>(key, referenceQueue);
}
@Override public boolean isAlive() {
Object keyRef = keyReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ interface PeekingIterator<E> extends Iterator<E> {

/** Returns an iterator that returns the first iteration followed by the second iteration. */
static <E> PeekingIterator<E> concat(PeekingIterator<E> first, PeekingIterator<E> second) {
return new PeekingIterator<E>() {
return new PeekingIterator<>() {
@Override public boolean hasNext() {
return first.hasNext() || second.hasNext();
}
Expand All @@ -130,7 +130,7 @@ static <E> PeekingIterator<E> concat(PeekingIterator<E> first, PeekingIterator<E
/** Returns an iterator that selects the greater element from the backing iterators. */
static <E> PeekingIterator<E> comparing(PeekingIterator<E> first,
PeekingIterator<E> second, Comparator<E> comparator) {
return new PeekingIterator<E>() {
return new PeekingIterator<>() {
@Override public boolean hasNext() {
return first.hasNext() || second.hasNext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ public void forEach(Consumer<? super V> action) {

@Override
public Iterator<V> iterator() {
return new Iterator<V>() {
return new Iterator<>() {
final Iterator<Entry<K, V>> iterator = entrySet().iterator();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ default void setRefreshesAfter(Duration duration) {
* A key-value pair that may include policy metadata for the cached entry. Unless otherwise
* specified, this is a value-based class, it can be assumed that the implementation is an
* immutable snapshot of the cached data at the time of this entry's creation, and it will not
* reflect changes afterwards.
* reflect changes afterward.
*/
interface CacheEntry<K, V> extends Map.Entry<K, V> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ static final class EntrySpliterator<K, V> implements Spliterator<Entry<K, V>> {
public void forEachRemaining(Consumer<? super Entry<K, V>> action) {
requireNonNull(action);
spliterator.forEachRemaining(entry -> {
var e = new WriteThroughEntry<K, V>(cache, entry.getKey(), entry.getValue());
var e = new WriteThroughEntry<>(cache, entry.getKey(), entry.getValue());
action.accept(e);
});
}
Expand All @@ -999,7 +999,7 @@ public void forEachRemaining(Consumer<? super Entry<K, V>> action) {
public boolean tryAdvance(Consumer<? super Entry<K, V>> action) {
requireNonNull(action);
return spliterator.tryAdvance(entry -> {
var e = new WriteThroughEntry<K, V>(cache, entry.getKey(), entry.getValue());
var e = new WriteThroughEntry<>(cache, entry.getKey(), entry.getValue());
action.accept(e);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.github.benmanes.caffeine.cache.RemovalCause.EXPLICIT;
import static com.github.benmanes.caffeine.cache.RemovalCause.REPLACED;
import static com.github.benmanes.caffeine.cache.testing.AsyncCacheSubject.assertThat;
import static com.github.benmanes.caffeine.cache.testing.CacheContext.intern;
import static com.github.benmanes.caffeine.cache.testing.CacheContextSubject.assertThat;
import static com.github.benmanes.caffeine.testing.Awaits.await;
import static com.github.benmanes.caffeine.testing.CollectionSubject.assertThat;
Expand Down Expand Up @@ -488,7 +489,7 @@ public void getAllFunction_exceeds(AsyncCache<Int, Int> cache, CacheContext cont
for (int i = 0; i < 10; i++) {
moreKeys.add(Int.valueOf(ThreadLocalRandom.current().nextInt()));
}
return Maps.toMap(moreKeys, Int::negate);
return intern(Maps.toMap(moreKeys, Int::negate));
}).join();

assertThat(result).containsExactlyKeys(context.absentKeys());
Expand Down Expand Up @@ -580,7 +581,7 @@ public void getAllFunction_present_ordered_exceeds(
for (int i = 0; i < 10; i++) {
moreKeys.add(Int.valueOf(ThreadLocalRandom.current().nextInt()));
}
return Maps.toMap(moreKeys, Int::negate);
return intern(Maps.toMap(moreKeys, Int::negate));
}).join();
assertThat(result).containsExactlyKeys(keys).inOrder();
}
Expand Down Expand Up @@ -808,7 +809,7 @@ public void getAllBifunction_exceeds(AsyncCache<Int, Int> cache, CacheContext co
for (int i = 0; i < 10; i++) {
moreKeys.add(Int.valueOf(ThreadLocalRandom.current().nextInt()));
}
return CompletableFuture.completedFuture(Maps.toMap(moreKeys, Int::negate));
return CompletableFuture.completedFuture(intern(Maps.toMap(moreKeys, Int::negate)));
}).join();

assertThat(result).containsExactlyKeys(context.absentKeys());
Expand Down Expand Up @@ -958,7 +959,7 @@ public void getAllBifunction_present_ordered_exceeds(
for (int i = 0; i < 10; i++) {
moreKeys.add(Int.valueOf(ThreadLocalRandom.current().nextInt()));
}
return CompletableFuture.completedFuture(Maps.toMap(moreKeys, Int::negate));
return CompletableFuture.completedFuture(intern(Maps.toMap(moreKeys, Int::negate)));
}).join();
assertThat(result).containsExactlyKeys(keys).inOrder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.github.benmanes.caffeine.cache.Pacer.TOLERANCE;
import static com.github.benmanes.caffeine.cache.RemovalCause.EXPIRED;
import static com.github.benmanes.caffeine.cache.testing.AsyncCacheSubject.assertThat;
import static com.github.benmanes.caffeine.cache.testing.CacheContext.intern;
import static com.github.benmanes.caffeine.cache.testing.CacheContextSubject.assertThat;
import static com.github.benmanes.caffeine.cache.testing.CacheSpec.Expiration.AFTER_ACCESS;
import static com.github.benmanes.caffeine.cache.testing.CacheSpec.Expiration.AFTER_WRITE;
Expand Down Expand Up @@ -313,14 +314,14 @@ public void put_replace(Cache<Int, Int> cache, CacheContext context) {
expireAfterAccess = {Expire.DISABLED, Expire.ONE_MINUTE},
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
public void put_weighted(Cache<Int, List<Int>> cache, CacheContext context) {
var value = CacheContext.intern(List.of(context.absentValue()));
var value = intern(List.of(context.absentValue()));
cache.put(context.absentKey(), value);
assertThat(context).hasWeightedSize(1);

context.ticker().advance(Duration.ofMinutes(1));
assertThat(context).hasWeightedSize(1);

var newValue = CacheContext.intern(List.copyOf(context.absent().values()));
var newValue = intern(List.copyOf(context.absent().values()));
cache.put(context.absentKey(), newValue);
assertThat(context).hasWeightedSize(context.absent().size());
}
Expand Down Expand Up @@ -573,7 +574,7 @@ public void getAll(AsyncCache<Int, Int> cache, CacheContext context) {
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
public void put_insert(AsyncCache<Int, Int> cache, CacheContext context) {
context.ticker().advance(Duration.ofMinutes(1));
cache.put(context.firstKey(), CacheContext.intern(context.absentValue().asFuture()));
cache.put(context.firstKey(), intern(context.absentValue().asFuture()));

runVariableExpiration(context);
assertThat(cache).hasSize(1);
Expand Down Expand Up @@ -734,11 +735,11 @@ public void clear(Map<Int, Int> map, CacheContext context) {
expireAfterAccess = {Expire.DISABLED, Expire.ONE_MINUTE},
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
public void putIfAbsent_weighted(Map<Int, List<Int>> map, CacheContext context) {
var value = CacheContext.intern(List.of(context.absentValue()));
var value = intern(List.of(context.absentValue()));
map.put(context.absentKey(), value);
context.ticker().advance(Duration.ofMinutes(1));

var newValue = CacheContext.intern(List.copyOf(context.absent().values()));
var newValue = intern(List.copyOf(context.absent().values()));
map.putIfAbsent(context.absentKey(), newValue);
assertThat(context).hasWeightedSize(context.absent().size());
}
Expand Down Expand Up @@ -1022,11 +1023,11 @@ public void computeIfAbsent_expiresInCompute(Map<Int, Int> map, CacheContext con
expireAfterAccess = {Expire.DISABLED, Expire.ONE_MINUTE},
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
public void computeIfAbsent_weighted(Map<Int, List<Int>> map, CacheContext context) {
var value = CacheContext.intern(List.of(context.absentValue()));
var value = intern(List.of(context.absentValue()));
map.put(context.absentKey(), value);
context.ticker().advance(Duration.ofMinutes(1));

var newValue = CacheContext.intern(List.copyOf(context.absent().values()));
var newValue = intern(List.copyOf(context.absent().values()));
map.computeIfAbsent(context.absentKey(), k -> newValue);
assertThat(context).hasWeightedSize(context.absent().size());
}
Expand Down Expand Up @@ -1243,11 +1244,11 @@ public void compute(Map<Int, Int> map, CacheContext context) {
expireAfterAccess = {Expire.DISABLED, Expire.ONE_MINUTE},
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
public void compute_weighted(Map<Int, List<Int>> map, CacheContext context) {
var value = CacheContext.intern(List.of(context.absentValue()));
var value = intern(List.of(context.absentValue()));
map.put(context.absentKey(), value);
context.ticker().advance(Duration.ofMinutes(1));

var newValue = CacheContext.intern(List.copyOf(context.absent().values()));
var newValue = intern(List.copyOf(context.absent().values()));
map.compute(context.absentKey(), (k, v) -> newValue);
assertThat(context).hasWeightedSize(context.absent().size());
}
Expand Down Expand Up @@ -1378,11 +1379,11 @@ public void merge(Map<Int, Int> map, CacheContext context) {
expireAfterAccess = {Expire.DISABLED, Expire.ONE_MINUTE},
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
public void merge_weighted(Cache<Int, List<Int>> cache, CacheContext context) {
var value = CacheContext.intern(List.of(context.absentValue()));
var value = intern(List.of(context.absentValue()));
cache.put(context.absentKey(), value);
context.ticker().advance(Duration.ofMinutes(1));

var newValue = CacheContext.intern(List.copyOf(context.absent().values()));
var newValue = intern(List.copyOf(context.absent().values()));
cache.asMap().merge(context.absentKey(), newValue,
(oldValue, v) -> { throw new AssertionError("Should never be called"); });
assertThat(context).hasWeightedSize(context.absent().size());
Expand Down
2 changes: 1 addition & 1 deletion examples/coalescing-bulkloader-reactor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ while the optimistic reloads are instead submitted to the sink. It's worth notin
}
```
The subscriber receives a batch of requests, each comprising of a key and a pending future result.
The subscriber receives a batch of requests, each consisting of a key and a pending future result.
It performs the synchronous load and then either completes the key's future with the corresponding
value or an exception if a failure occurs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ tasks.jar {
}

tasks.withType<Javadoc>().configureEach {
setFailOnError(false)
isFailOnError = false
javadocOptions {
links(
"https://checkerframework.org/api/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
}

// Gradle rewrites ErrorProne's dependency on Caffeine to a project dependency, which then fails.
// Instead we have to download and trick the build to put the jar on the compiler's classpath.
// Instead, we have to download and trick the build to put the jar on the compiler's classpath.
val downloadCaffeine by tasks.registering {
val version = libs.versions.caffeine.get()
inputs.property("version", version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public Map<K, V> getAll(Set<? extends K> keys) {
*/
protected Map<K, Expirable<V>> getAndFilterExpiredEntries(
Set<? extends K> keys, boolean updateAccessTime) {
var result = new HashMap<K, Expirable<V>>(cache.getAllPresent(keys));
var result = new HashMap<>(cache.getAllPresent(keys));

int[] expired = { 0 };
long[] millis = { 0L };
Expand Down Expand Up @@ -1238,7 +1238,7 @@ public Cache.Entry<K, V> next() {
current = cursor;
cursor = null;
@SuppressWarnings("NullAway")
var entry = new EntryProxy<K, V>(copyOf(current.getKey()), copyValue(current.getValue()));
var entry = new EntryProxy<>(copyOf(current.getKey()), copyValue(current.getValue()));
return entry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ private UnmodifiableIterable(Iterable<E> delegate) {
}
@Override public Iterator<E> iterator() {
var iterator = delegate.iterator();
return new Iterator<E>() {
return new Iterator<>() {
@Override public boolean hasNext() {
return iterator.hasNext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void register(CacheEntryListenerConfiguration<K, V> configuration) {
configuration.getCacheEntryEventFilterFactory().create());
}

var registration = new Registration<K, V>(configuration, filter, listener);
var registration = new Registration<>(configuration, filter, listener);
dispatchQueues.putIfAbsent(registration, new ConcurrentHashMap<>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public <T> T unwrap(Class<T> clazz) {

@Override
public Iterator<CacheEntryEvent<? extends K, ? extends V>> iterator() {
return new Iterator<CacheEntryEvent<? extends K, ? extends V>>() {
return new Iterator<>() {
boolean hasNext = true;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public final class IndicatorResetCountMin4 implements Frequency {
private final ClimberResetCountMin4 sketch;

Indicator indicator;
final Indicator indicator;

public IndicatorResetCountMin4(Config config) {
this.sketch = new ClimberResetCountMin4(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* maximum frequency of an element. The size of the sample in relation to the cache size can be
* controlled with a sample factor. Instead of halving the popularity of elements a random element
* is dropped when table is full.
*
* <p>
* This class is used to check the feasibility of using TinyTable instead of CountMin Sketch.
*
* @author [email protected] (Gil Einziger)
Expand All @@ -39,7 +39,7 @@ public final class RandomRemovalFrequencyTable implements Frequency {
/** controls both the max count and how many items are remembered (the sum) */
private static final int sampleFactor = 8;

/** a place holder for TinyTable */
/** a placeholder for TinyTable */
private final Map<Long, Integer> table;
/** used to dropped items at random */
private final Random random;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* empty) isLastIndex (set bit for last in chain/empty bit for not last in chain). Both indexes are
* assumed to be 64 bits, (longs) for efficiency and simplicity. The technique update the indexes
* upon addition/removal.
*
* <p>
* Paper link:
* http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/2015/CS/CS-2015-03.pdf
* Presentation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private final class Execute extends Command {
}
}

/** A command to shutdown the policy and finalize the statistics. */
/** A command to shut down the policy and finalize the statistics. */
private final class Finish extends Command {
@Override public void execute() {
policy.finished();
Expand Down
Loading

0 comments on commit e872e2e

Please sign in to comment.