jsedding commented on code in PR #2819: URL: https://github.com/apache/jackrabbit-oak/pull/2819#discussion_r3009046004
########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CaffeineCacheAdapter.java: ########## @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.RemovalCause; +import com.github.benmanes.caffeine.cache.stats.CacheStats; +import org.jetbrains.annotations.NotNull; + +/** + * {@link OakCache} adapter wrapping a Caffeine {@link Cache}. + */ +class CaffeineCacheAdapter<K, V> implements OakCache<K, V> { + + private final Cache<K, V> cache; + + CaffeineCacheAdapter(Cache<K, V> cache) { + this.cache = cache; + } + + @Override + public V getIfPresent(@NotNull K key) { + return cache.getIfPresent(key); + } + + @Override + public V get(@NotNull K key, @NotNull Callable<? extends V> valueLoader) throws ExecutionException { + try { + return cache.get(key, k -> callUnchecked(valueLoader)); + } catch (CacheComputationException e) { + throw new ExecutionException(e.getCause()); + } catch (RuntimeException e) { + throw new ExecutionException(e); + } + } + + @Override + public void put(@NotNull K key, @NotNull V value) { + cache.put(key, value); + } + + @Override + public void invalidate(@NotNull K key) { + cache.invalidate(key); + } + + @Override + public void invalidateAll() { + cache.invalidateAll(); + } + + @Override + public void invalidateAll(@NotNull Iterable<? extends K> keys) { + cache.invalidateAll(keys); + } + + @Override + public long estimatedSize() { + return cache.estimatedSize(); + } + + @Override + @NotNull + public OakCacheStats stats() { + CacheStats s = cache.stats(); + return new OakCacheStats( + s.hitCount(), s.missCount(), + s.loadSuccessCount(), s.loadFailureCount(), + s.totalLoadTime(), s.evictionCount()); + } + + @Override + @NotNull + public ConcurrentMap<K, V> asMap() { + return cache.asMap(); + } + + @Override + @NotNull + public Map<K, V> getAllPresent(@NotNull Iterable<? extends K> keys) { + return cache.getAllPresent(keys); + } + + @Override + public void cleanUp() { + cache.cleanUp(); + } + + /** + * Maps a Caffeine {@code RemovalCause} to the Oak-neutral {@link OakRemovalCause}. + */ + static OakRemovalCause toOakCause(RemovalCause cause) { Review Comment: I would prefer using the term "eviction" in the Oak-APIs. To me "eviction" encapsulates the concept better that something was removed in order to make space. "Removed" doesn't convey that same meaning, its meaning is less precise. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CaffeineCacheAdapter.java: ########## @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.RemovalCause; +import com.github.benmanes.caffeine.cache.stats.CacheStats; +import org.jetbrains.annotations.NotNull; + +/** + * {@link OakCache} adapter wrapping a Caffeine {@link Cache}. + */ +class CaffeineCacheAdapter<K, V> implements OakCache<K, V> { Review Comment: I would just call this class `CaffeineCache` or `CaffeineOakCache`. The word "adapter" seems a bit misleading to me when I am looking at this from the Oak perspective. If the Caffeine library was to provide an `OakCache` compatible implementation, then that could be called an "adapter" IMHO. For us, Caffeine is just the implementation. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CaffeineCacheAdapter.java: ########## @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.RemovalCause; +import com.github.benmanes.caffeine.cache.stats.CacheStats; +import org.jetbrains.annotations.NotNull; + +/** + * {@link OakCache} adapter wrapping a Caffeine {@link Cache}. + */ +class CaffeineCacheAdapter<K, V> implements OakCache<K, V> { + + private final Cache<K, V> cache; + + CaffeineCacheAdapter(Cache<K, V> cache) { + this.cache = cache; + } + + @Override + public V getIfPresent(@NotNull K key) { + return cache.getIfPresent(key); + } + + @Override + public V get(@NotNull K key, @NotNull Callable<? extends V> valueLoader) throws ExecutionException { + try { + return cache.get(key, k -> callUnchecked(valueLoader)); + } catch (CacheComputationException e) { + throw new ExecutionException(e.getCause()); + } catch (RuntimeException e) { + throw new ExecutionException(e); + } + } + + @Override + public void put(@NotNull K key, @NotNull V value) { + cache.put(key, value); + } + + @Override + public void invalidate(@NotNull K key) { + cache.invalidate(key); + } + + @Override + public void invalidateAll() { + cache.invalidateAll(); + } + + @Override + public void invalidateAll(@NotNull Iterable<? extends K> keys) { + cache.invalidateAll(keys); + } + + @Override + public long estimatedSize() { + return cache.estimatedSize(); + } + + @Override + @NotNull + public OakCacheStats stats() { + CacheStats s = cache.stats(); + return new OakCacheStats( + s.hitCount(), s.missCount(), + s.loadSuccessCount(), s.loadFailureCount(), + s.totalLoadTime(), s.evictionCount()); + } + + @Override + @NotNull + public ConcurrentMap<K, V> asMap() { + return cache.asMap(); + } + + @Override + @NotNull + public Map<K, V> getAllPresent(@NotNull Iterable<? extends K> keys) { + return cache.getAllPresent(keys); + } + + @Override + public void cleanUp() { + cache.cleanUp(); + } + + /** + * Maps a Caffeine {@code RemovalCause} to the Oak-neutral {@link OakRemovalCause}. + */ + static OakRemovalCause toOakCause(RemovalCause cause) { + return switch (cause) { + case EXPLICIT -> OakRemovalCause.EXPLICIT; + case REPLACED -> OakRemovalCause.REPLACED; + case SIZE -> OakRemovalCause.SIZE; + case EXPIRED -> OakRemovalCause.EXPIRED; + case COLLECTED -> OakRemovalCause.COLLECTED; + }; + } + + private static <V> V callUnchecked(Callable<? extends V> valueLoader) { + try { + return valueLoader.call(); + } catch (Exception e) { + throw new CacheComputationException(e); + } + } +} + +/** + * {@link OakLoadingCache} adapter wrapping a Caffeine {@link LoadingCache}. + * + * <p>TODO OAK-TASK16: per {@code TASKS.md}, remove this temporary bridge in + * TASK-16 once the migration cleanup drops the Oak-visible loading-cache + * compatibility layer.</p> + */ +class CaffeineLoadingCacheAdapter<K, V> extends CaffeineCacheAdapter<K, V> implements OakLoadingCache<K, V> { + + private final LoadingCache<K, V> loadingCache; + + CaffeineLoadingCacheAdapter(LoadingCache<K, V> loadingCache) { + super(loadingCache); + this.loadingCache = loadingCache; + } + + @Override + @NotNull + public V get(@NotNull K key) throws ExecutionException { Review Comment: Same question as with `public V get(@NotNull K key, @NotNull Callable<? extends V> valueLoader) throws ExecutionException`: should we really throw a checked exception here? Guava-style is to throw `ExecutionException`, Caffeine-style is to throw no checked exception. Caffeine still documents four exceptions ``` * @throws NullPointerException if the specified key is null * @throws IllegalStateException if the computation detectably attempts a recursive update to this * cache that would otherwise never complete * @throws CompletionException if a checked exception was thrown while loading the value * @throws RuntimeException or Error if the {@link CacheLoader} does so, in which case the mapping * is left unestablished ``` I would go Caffeine-style. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CaffeineCacheAdapter.java: ########## @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; Review Comment: I would consider creating a sub-package `caffeine` or even `impl.caffeine`. This sub-package should NOT be exported in OSGi. It should contain only the Caffeine-based implementation classes. That way, it is less likely that any of the implementation classes slip through and become API by accident. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/OakCache.java: ########## @@ -56,21 +53,19 @@ public interface OakCache<K, V> { /** * Returns the value associated with {@code key}, computing it via - * {@code mappingFunction} and caching the result if it was absent. + * {@code valueLoader} and caching the result if it was absent. * - * <p>Matches Caffeine's {@code Cache.get(K, Function)} contract: any exception - * thrown by the mapping function propagates as an unchecked - * {@code RuntimeException} or {@code CompletionException}. Implementations - * backed by CacheLIRS bridge internally by wrapping any checked - * {@code ExecutionException} into {@code CompletionException}.</p> + * <p>Preserves the legacy Oak-visible cache contract: failures from the loader + * are exposed as {@link ExecutionException}.</p> * - * @param key the key whose associated value is to be returned (must not be null) - * @param mappingFunction the function to compute a value if the key is absent (must not be null) + * @param key the key whose associated value is to be returned (must not be null) + * @param valueLoader the loader used to compute a value if the key is absent (must not be null) * @return the current (existing or computed) value, or {@code null} if the - * mapping function returns {@code null} + * loader returns {@code null} + * @throws ExecutionException if the value cannot be loaded */ @Nullable - V get(@NotNull K key, @NotNull Function<? super K, ? extends V> mappingFunction); + V get(@NotNull K key, @NotNull Callable<? extends V> valueLoader) throws ExecutionException; Review Comment: See my comments on the `CaffeineCacheAdapter` class. I think we should go with the Caffeine-style API. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/OakCacheBuilder.java: ########## @@ -0,0 +1,464 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.time.Duration; +import java.util.Locale; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; + +import org.apache.jackrabbit.guava.common.cache.CacheLoader; +import org.jetbrains.annotations.NotNull; + +/** + * Builder for {@link OakCache} and {@link OakLoadingCache} instances. + * + * <p>The backing implementation is chosen by a two-level resolution:</p> + * <ol> + * <li><strong>Per-instance override</strong> — {@link #implementation(CacheImplementation)} + * pins this cache to one backend, regardless of any global setting.</li> + * <li><strong>Global default</strong> — the system property {@code oak.cache.type} + * ({@code lirs} or {@code caffeine}, case-insensitive); defaults to {@code lirs}.</li> + * </ol> + * + * <p>Example:</p> + * <pre>{@code + * OakCache<String, NodeState> cache = OakCacheBuilder.<String, NodeState>newBuilder() + * .module("DocumentNodeStore") + * .maximumWeight(64 * 1024 * 1024) + * .weigher((k, v) -> v.estimateMemory()) + * .recordStats() + * .build(); + * }</pre> + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + */ +public final class OakCacheBuilder<K, V> { Review Comment: IMHO, it would be easier to have a `CaffeineOakCacheBuilder` implementation that directly delegates all calls to the `Caffeine` class. No need to maintain duplicates of all fields in our own class. Even if we were to chose to have multiple cache implementations, then we could enforce via the API that the implementation has to be chosen first, and return the matching builder implementation. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CaffeineCacheAdapter.java: ########## @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.RemovalCause; +import com.github.benmanes.caffeine.cache.stats.CacheStats; +import org.jetbrains.annotations.NotNull; + +/** + * {@link OakCache} adapter wrapping a Caffeine {@link Cache}. + */ +class CaffeineCacheAdapter<K, V> implements OakCache<K, V> { + + private final Cache<K, V> cache; + + CaffeineCacheAdapter(Cache<K, V> cache) { + this.cache = cache; + } + + @Override + public V getIfPresent(@NotNull K key) { + return cache.getIfPresent(key); + } + + @Override + public V get(@NotNull K key, @NotNull Callable<? extends V> valueLoader) throws ExecutionException { + try { + return cache.get(key, k -> callUnchecked(valueLoader)); + } catch (CacheComputationException e) { + throw new ExecutionException(e.getCause()); + } catch (RuntimeException e) { + throw new ExecutionException(e); + } + } + + @Override + public void put(@NotNull K key, @NotNull V value) { + cache.put(key, value); + } + + @Override + public void invalidate(@NotNull K key) { + cache.invalidate(key); + } + + @Override + public void invalidateAll() { + cache.invalidateAll(); + } + + @Override + public void invalidateAll(@NotNull Iterable<? extends K> keys) { + cache.invalidateAll(keys); + } + + @Override + public long estimatedSize() { + return cache.estimatedSize(); + } + + @Override + @NotNull + public OakCacheStats stats() { + CacheStats s = cache.stats(); + return new OakCacheStats( + s.hitCount(), s.missCount(), + s.loadSuccessCount(), s.loadFailureCount(), + s.totalLoadTime(), s.evictionCount()); + } + + @Override + @NotNull + public ConcurrentMap<K, V> asMap() { + return cache.asMap(); + } + + @Override + @NotNull + public Map<K, V> getAllPresent(@NotNull Iterable<? extends K> keys) { + return cache.getAllPresent(keys); + } + + @Override + public void cleanUp() { + cache.cleanUp(); + } + + /** + * Maps a Caffeine {@code RemovalCause} to the Oak-neutral {@link OakRemovalCause}. + */ + static OakRemovalCause toOakCause(RemovalCause cause) { + return switch (cause) { + case EXPLICIT -> OakRemovalCause.EXPLICIT; + case REPLACED -> OakRemovalCause.REPLACED; + case SIZE -> OakRemovalCause.SIZE; + case EXPIRED -> OakRemovalCause.EXPIRED; + case COLLECTED -> OakRemovalCause.COLLECTED; Review Comment: Should we not have a "default" case that throws an exception? ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CacheImplementation.java: ########## @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +/** + * Selects the backing cache implementation used by {@link OakCacheBuilder}. + * + * <p>Pass to {@link OakCacheBuilder#implementation(CacheImplementation)} to pin a specific + * cache to one backend, overriding the global {@code oak.cache.type} system property. + * When no per-instance override is set, the builder resolves the implementation from + * {@code System.getProperty("oak.cache.type", "lirs")}.</p> + */ +public enum CacheImplementation { + + /** LIRS (Low Inter-reference Recency Set) eviction, backed by {@code CacheLIRS}. */ + LIRS, Review Comment: I don't think we need a LIRS cache implementation. Caffeine's W-TinyLRU seems to be an all-round better strategy. Ultimately, we don't care about the implementation details, as long as the cache "just works". Getting rid of the LIRS cache implementation means we can delete code and we won't have to maintain that code. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CaffeineCacheAdapter.java: ########## @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.RemovalCause; +import com.github.benmanes.caffeine.cache.stats.CacheStats; +import org.jetbrains.annotations.NotNull; + +/** + * {@link OakCache} adapter wrapping a Caffeine {@link Cache}. + */ +class CaffeineCacheAdapter<K, V> implements OakCache<K, V> { + + private final Cache<K, V> cache; + + CaffeineCacheAdapter(Cache<K, V> cache) { + this.cache = cache; + } + + @Override + public V getIfPresent(@NotNull K key) { + return cache.getIfPresent(key); + } + + @Override + public V get(@NotNull K key, @NotNull Callable<? extends V> valueLoader) throws ExecutionException { Review Comment: The equivalent method in Caffeine takes a mapping function `Function<? super K, ? extends V>` instead of a `Callable<? extends V>`, and it throws no checked exception. Do we want to stick with the Guava-style API here? Or do we want to move to the (more modern?) Caffeine-style API? The latter likely requires slightly more adjustments in our code. The latter might make our lives slightly easier in the future. I would go with the Caffeine-style API. Thoughts? ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/OakCacheBuilder.java: ########## @@ -0,0 +1,464 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.time.Duration; +import java.util.Locale; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; + +import org.apache.jackrabbit.guava.common.cache.CacheLoader; +import org.jetbrains.annotations.NotNull; + +/** + * Builder for {@link OakCache} and {@link OakLoadingCache} instances. + * + * <p>The backing implementation is chosen by a two-level resolution:</p> + * <ol> + * <li><strong>Per-instance override</strong> — {@link #implementation(CacheImplementation)} + * pins this cache to one backend, regardless of any global setting.</li> + * <li><strong>Global default</strong> — the system property {@code oak.cache.type} + * ({@code lirs} or {@code caffeine}, case-insensitive); defaults to {@code lirs}.</li> + * </ol> + * + * <p>Example:</p> + * <pre>{@code + * OakCache<String, NodeState> cache = OakCacheBuilder.<String, NodeState>newBuilder() + * .module("DocumentNodeStore") + * .maximumWeight(64 * 1024 * 1024) + * .weigher((k, v) -> v.estimateMemory()) + * .recordStats() + * .build(); + * }</pre> + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + */ +public final class OakCacheBuilder<K, V> { + + // Common fields + private String module; + private CacheImplementation implementation; + private long maximumWeight = -1; + private long maximumSize = -1; + private OakWeigher<K, V> weigher; + private OakRemovalListener<K, V> removalListener; + private boolean recordStats; + // Caffeine-only time-based expiry + private Duration expireAfterAccess; + private Duration expireAfterWrite; + private Duration refreshAfterWrite; + // LIRS-specific tuning + private int segmentCount = -1; + private int stackMoveDistance = -1; + private long averageWeight = -1; + + private OakCacheBuilder() { + } + + /** + * Creates a new builder with no pre-configured settings. + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + * @return a new builder instance + */ + @NotNull + public static <K, V> OakCacheBuilder<K, V> newBuilder() { + return new OakCacheBuilder<>(); + } + + /** + * Sets a module label used in logging and diagnostics. + * + * @param module the module name (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> module(@NotNull String module) { + if (module == null || module.isEmpty()) { + throw new IllegalArgumentException("module must not be null or empty"); + } + this.module = module; + return this; + } + + /** + * Pins this cache to the given implementation, overriding the global + * {@code oak.cache.type} system property. + * + * @param implementation the implementation to use (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> implementation(@NotNull CacheImplementation implementation) { + if (implementation == null) { + throw new IllegalArgumentException("implementation must not be null"); + } + this.implementation = implementation; + return this; + } + + /** + * Sets the maximum total weight of entries the cache may hold. + * Must be used together with {@link #weigher(OakWeigher)} and may not be + * combined with {@link #maximumSize(long)}. + * + * @param maximumWeight the maximum weight (must be non-negative) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> maximumWeight(long maximumWeight) { + if (maximumWeight < 0) { + throw new IllegalArgumentException("maximumWeight must be non-negative, got: " + maximumWeight); + } + this.maximumWeight = maximumWeight; + return this; + } + + /** + * Sets the maximum number of entries the cache may hold. + * May not be combined with {@link #maximumWeight(long)}. + * + * @param maximumSize the maximum entry count (must be non-negative) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> maximumSize(long maximumSize) { + if (maximumSize < 0) { + throw new IllegalArgumentException("maximumSize must be non-negative, got: " + maximumSize); + } + this.maximumSize = maximumSize; + return this; + } + + /** + * Sets the weigher used to determine the weight of each cache entry. + * Requires {@link #maximumWeight(long)}. + * + * @param weigher the weigher (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> weigher(@NotNull OakWeigher<K, V> weigher) { + if (weigher == null) { + throw new IllegalArgumentException("weigher must not be null"); + } + this.weigher = weigher; + return this; + } + + /** + * Registers a listener to be notified when entries are removed from the cache. + * + * @param removalListener the listener (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> removalListener(@NotNull OakRemovalListener<K, V> removalListener) { Review Comment: I would rather see this method as `public OakCacheBuilder<K, V> evictionListener(@NotNull OakEvictionListener<? super K, ? super V> evictionListener)`. BTW, the generics are wrong. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/OakCacheBuilder.java: ########## @@ -0,0 +1,464 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.time.Duration; +import java.util.Locale; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; + +import org.apache.jackrabbit.guava.common.cache.CacheLoader; +import org.jetbrains.annotations.NotNull; + +/** + * Builder for {@link OakCache} and {@link OakLoadingCache} instances. + * + * <p>The backing implementation is chosen by a two-level resolution:</p> + * <ol> + * <li><strong>Per-instance override</strong> — {@link #implementation(CacheImplementation)} + * pins this cache to one backend, regardless of any global setting.</li> + * <li><strong>Global default</strong> — the system property {@code oak.cache.type} + * ({@code lirs} or {@code caffeine}, case-insensitive); defaults to {@code lirs}.</li> + * </ol> + * + * <p>Example:</p> + * <pre>{@code + * OakCache<String, NodeState> cache = OakCacheBuilder.<String, NodeState>newBuilder() + * .module("DocumentNodeStore") + * .maximumWeight(64 * 1024 * 1024) + * .weigher((k, v) -> v.estimateMemory()) + * .recordStats() + * .build(); + * }</pre> + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + */ +public final class OakCacheBuilder<K, V> { + + // Common fields + private String module; + private CacheImplementation implementation; + private long maximumWeight = -1; + private long maximumSize = -1; + private OakWeigher<K, V> weigher; + private OakRemovalListener<K, V> removalListener; + private boolean recordStats; + // Caffeine-only time-based expiry + private Duration expireAfterAccess; + private Duration expireAfterWrite; + private Duration refreshAfterWrite; + // LIRS-specific tuning + private int segmentCount = -1; + private int stackMoveDistance = -1; + private long averageWeight = -1; + + private OakCacheBuilder() { + } + + /** + * Creates a new builder with no pre-configured settings. + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + * @return a new builder instance + */ + @NotNull + public static <K, V> OakCacheBuilder<K, V> newBuilder() { + return new OakCacheBuilder<>(); + } + + /** + * Sets a module label used in logging and diagnostics. + * + * @param module the module name (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> module(@NotNull String module) { + if (module == null || module.isEmpty()) { + throw new IllegalArgumentException("module must not be null or empty"); + } + this.module = module; + return this; + } + + /** + * Pins this cache to the given implementation, overriding the global + * {@code oak.cache.type} system property. + * + * @param implementation the implementation to use (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> implementation(@NotNull CacheImplementation implementation) { + if (implementation == null) { + throw new IllegalArgumentException("implementation must not be null"); + } + this.implementation = implementation; + return this; + } + + /** + * Sets the maximum total weight of entries the cache may hold. + * Must be used together with {@link #weigher(OakWeigher)} and may not be + * combined with {@link #maximumSize(long)}. + * + * @param maximumWeight the maximum weight (must be non-negative) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> maximumWeight(long maximumWeight) { + if (maximumWeight < 0) { + throw new IllegalArgumentException("maximumWeight must be non-negative, got: " + maximumWeight); + } + this.maximumWeight = maximumWeight; + return this; + } + + /** + * Sets the maximum number of entries the cache may hold. + * May not be combined with {@link #maximumWeight(long)}. + * + * @param maximumSize the maximum entry count (must be non-negative) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> maximumSize(long maximumSize) { + if (maximumSize < 0) { + throw new IllegalArgumentException("maximumSize must be non-negative, got: " + maximumSize); + } + this.maximumSize = maximumSize; + return this; + } + + /** + * Sets the weigher used to determine the weight of each cache entry. + * Requires {@link #maximumWeight(long)}. + * + * @param weigher the weigher (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> weigher(@NotNull OakWeigher<K, V> weigher) { Review Comment: The generics are wrong. ```suggestion public OakCacheBuilder<K, V> weigher(@NotNull OakWeigher<? super K, ? extends V> weigher) { ``` ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/LirsCacheAdapter.java: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; + +import org.apache.jackrabbit.guava.common.cache.CacheStats; +import org.apache.jackrabbit.guava.common.cache.RemovalCause; +import org.jetbrains.annotations.NotNull; + +/** + * {@link OakCache} adapter wrapping a {@link CacheLIRS} instance. + * + * <p>Exposes the checked {@link ExecutionException} contract used by the + * legacy Oak-visible cache API.</p> + */ +class LirsCacheAdapter<K, V> implements OakCache<K, V> { Review Comment: I would drop this class and invest the effort into refactoring code that uses the LIRS cache instead of into keeping the LIRS cache alive. IIUC that's in-line with @thomasmueller 's line of thought. Is that right? ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/OakCacheStatsAdapter.java: ########## @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.util.Map; + +import org.apache.jackrabbit.guava.common.cache.CacheStats; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Exposes an {@link OakCache}'s statistics via the {@link org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean} + * interface by bridging {@link OakCacheStats} to the Guava shim {@link CacheStats} expected + * by {@link AbstractCacheStats}. + * + * <p>The Guava return type from {@link #getCurrentStats()} is kept until TASK-16 updates + * the base class to use {@link OakCacheStats} directly.</p> Review Comment: Can you please explain why this needs to be delayed? `getCurrentStatus` is protected and we control all implementations. Should this not allow us to make this change rather than introduce this class temporarily? ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/OakCacheBuilder.java: ########## @@ -0,0 +1,464 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.time.Duration; +import java.util.Locale; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; + +import org.apache.jackrabbit.guava.common.cache.CacheLoader; +import org.jetbrains.annotations.NotNull; + +/** + * Builder for {@link OakCache} and {@link OakLoadingCache} instances. + * + * <p>The backing implementation is chosen by a two-level resolution:</p> + * <ol> + * <li><strong>Per-instance override</strong> — {@link #implementation(CacheImplementation)} + * pins this cache to one backend, regardless of any global setting.</li> + * <li><strong>Global default</strong> — the system property {@code oak.cache.type} + * ({@code lirs} or {@code caffeine}, case-insensitive); defaults to {@code lirs}.</li> + * </ol> + * + * <p>Example:</p> + * <pre>{@code + * OakCache<String, NodeState> cache = OakCacheBuilder.<String, NodeState>newBuilder() + * .module("DocumentNodeStore") + * .maximumWeight(64 * 1024 * 1024) + * .weigher((k, v) -> v.estimateMemory()) + * .recordStats() + * .build(); + * }</pre> + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + */ +public final class OakCacheBuilder<K, V> { + + // Common fields + private String module; + private CacheImplementation implementation; + private long maximumWeight = -1; + private long maximumSize = -1; + private OakWeigher<K, V> weigher; + private OakRemovalListener<K, V> removalListener; + private boolean recordStats; + // Caffeine-only time-based expiry + private Duration expireAfterAccess; + private Duration expireAfterWrite; + private Duration refreshAfterWrite; + // LIRS-specific tuning + private int segmentCount = -1; + private int stackMoveDistance = -1; + private long averageWeight = -1; + + private OakCacheBuilder() { + } + + /** + * Creates a new builder with no pre-configured settings. + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + * @return a new builder instance + */ + @NotNull + public static <K, V> OakCacheBuilder<K, V> newBuilder() { + return new OakCacheBuilder<>(); + } + + /** + * Sets a module label used in logging and diagnostics. + * + * @param module the module name (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> module(@NotNull String module) { + if (module == null || module.isEmpty()) { + throw new IllegalArgumentException("module must not be null or empty"); + } + this.module = module; + return this; + } + + /** + * Pins this cache to the given implementation, overriding the global + * {@code oak.cache.type} system property. + * + * @param implementation the implementation to use (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> implementation(@NotNull CacheImplementation implementation) { Review Comment: I don't think we need this. I think we can safely drop the LIRS cache and go with Caffeine for everything. ########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/OakCacheBuilder.java: ########## @@ -0,0 +1,464 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.cache; + +import java.time.Duration; +import java.util.Locale; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; + +import org.apache.jackrabbit.guava.common.cache.CacheLoader; +import org.jetbrains.annotations.NotNull; + +/** + * Builder for {@link OakCache} and {@link OakLoadingCache} instances. + * + * <p>The backing implementation is chosen by a two-level resolution:</p> + * <ol> + * <li><strong>Per-instance override</strong> — {@link #implementation(CacheImplementation)} + * pins this cache to one backend, regardless of any global setting.</li> + * <li><strong>Global default</strong> — the system property {@code oak.cache.type} + * ({@code lirs} or {@code caffeine}, case-insensitive); defaults to {@code lirs}.</li> + * </ol> + * + * <p>Example:</p> + * <pre>{@code + * OakCache<String, NodeState> cache = OakCacheBuilder.<String, NodeState>newBuilder() + * .module("DocumentNodeStore") + * .maximumWeight(64 * 1024 * 1024) + * .weigher((k, v) -> v.estimateMemory()) + * .recordStats() + * .build(); + * }</pre> + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + */ +public final class OakCacheBuilder<K, V> { + + // Common fields + private String module; + private CacheImplementation implementation; + private long maximumWeight = -1; + private long maximumSize = -1; + private OakWeigher<K, V> weigher; + private OakRemovalListener<K, V> removalListener; + private boolean recordStats; + // Caffeine-only time-based expiry + private Duration expireAfterAccess; + private Duration expireAfterWrite; + private Duration refreshAfterWrite; + // LIRS-specific tuning + private int segmentCount = -1; + private int stackMoveDistance = -1; + private long averageWeight = -1; + + private OakCacheBuilder() { + } + + /** + * Creates a new builder with no pre-configured settings. + * + * @param <K> the type of cache keys + * @param <V> the type of cache values + * @return a new builder instance + */ + @NotNull + public static <K, V> OakCacheBuilder<K, V> newBuilder() { + return new OakCacheBuilder<>(); + } + + /** + * Sets a module label used in logging and diagnostics. + * + * @param module the module name (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> module(@NotNull String module) { + if (module == null || module.isEmpty()) { + throw new IllegalArgumentException("module must not be null or empty"); + } + this.module = module; + return this; + } + + /** + * Pins this cache to the given implementation, overriding the global + * {@code oak.cache.type} system property. + * + * @param implementation the implementation to use (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> implementation(@NotNull CacheImplementation implementation) { + if (implementation == null) { + throw new IllegalArgumentException("implementation must not be null"); + } + this.implementation = implementation; + return this; + } + + /** + * Sets the maximum total weight of entries the cache may hold. + * Must be used together with {@link #weigher(OakWeigher)} and may not be + * combined with {@link #maximumSize(long)}. + * + * @param maximumWeight the maximum weight (must be non-negative) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> maximumWeight(long maximumWeight) { + if (maximumWeight < 0) { + throw new IllegalArgumentException("maximumWeight must be non-negative, got: " + maximumWeight); + } + this.maximumWeight = maximumWeight; + return this; + } + + /** + * Sets the maximum number of entries the cache may hold. + * May not be combined with {@link #maximumWeight(long)}. + * + * @param maximumSize the maximum entry count (must be non-negative) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> maximumSize(long maximumSize) { + if (maximumSize < 0) { + throw new IllegalArgumentException("maximumSize must be non-negative, got: " + maximumSize); + } + this.maximumSize = maximumSize; + return this; + } + + /** + * Sets the weigher used to determine the weight of each cache entry. + * Requires {@link #maximumWeight(long)}. + * + * @param weigher the weigher (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> weigher(@NotNull OakWeigher<K, V> weigher) { + if (weigher == null) { + throw new IllegalArgumentException("weigher must not be null"); + } + this.weigher = weigher; + return this; + } + + /** + * Registers a listener to be notified when entries are removed from the cache. + * + * @param removalListener the listener (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> removalListener(@NotNull OakRemovalListener<K, V> removalListener) { + if (removalListener == null) { + throw new IllegalArgumentException("removalListener must not be null"); + } + this.removalListener = removalListener; + return this; + } + + /** + * Enables collection of cache statistics accessible via {@link OakCache#stats()}. + * + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> recordStats() { + this.recordStats = true; + return this; + } + + /** + * Sets how long entries may remain in the cache after their last access. + * Applies to the Caffeine backend only; silently ignored for LIRS. + * + * @param duration the maximum idle duration (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> expireAfterAccess(@NotNull Duration duration) { + if (duration == null) { + throw new IllegalArgumentException("duration must not be null"); + } + this.expireAfterAccess = duration; + return this; + } + + /** + * Sets how long entries may remain in the cache after they were written. + * Applies to the Caffeine backend only; silently ignored for LIRS. + * + * @param duration the maximum age after write (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> expireAfterWrite(@NotNull Duration duration) { + if (duration == null) { + throw new IllegalArgumentException("duration must not be null"); + } + this.expireAfterWrite = duration; + return this; + } + + /** + * Sets how soon a loading cache should automatically refresh entries after write. + * Applies to the Caffeine backend only; requires {@link #build(OakCacheLoader)} + * and is ignored for LIRS. + * + * @param duration the refresh interval (must not be null) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> refreshAfterWrite(@NotNull Duration duration) { + if (duration == null) { + throw new IllegalArgumentException("duration must not be null"); + } + this.refreshAfterWrite = duration; + return this; + } + + /** + * Sets the number of LIRS segments. Applies to the LIRS backend only. + * + * @param segmentCount the number of segments (must be positive) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> segmentCount(int segmentCount) { + if (segmentCount <= 0) { + throw new IllegalArgumentException("segmentCount must be positive, got: " + segmentCount); + } + this.segmentCount = segmentCount; + return this; + } + + /** + * Sets the LIRS stack move distance. Applies to the LIRS backend only. + * + * @param stackMoveDistance the stack move distance (must be non-negative) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> stackMoveDistance(int stackMoveDistance) { + if (stackMoveDistance < 0) { + throw new IllegalArgumentException("stackMoveDistance must be non-negative, got: " + stackMoveDistance); + } + this.stackMoveDistance = stackMoveDistance; + return this; + } + + /** + * Sets the average expected weight per entry for LIRS sizing. + * Applies to the LIRS backend only and requires {@link #maximumWeight(long)}. + * + * @param averageWeight the average entry weight (must be positive and + * less than or equal to {@link Integer#MAX_VALUE}) + * @return this builder + */ + @NotNull + public OakCacheBuilder<K, V> averageWeight(long averageWeight) { + if (averageWeight <= 0) { + throw new IllegalArgumentException("averageWeight must be positive, got: " + averageWeight); + } + this.averageWeight = averageWeight; + return this; + } Review Comment: Remove these methods. They are specific to the LIRS cache implementation. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
