jsedding commented on code in PR #2819: URL: https://github.com/apache/jackrabbit-oak/pull/2819#discussion_r3022383111
########## oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/impl/CacheBuilder.java: ########## @@ -0,0 +1,471 @@ +/* + * 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.api.impl; + +import java.time.Duration; +import java.util.Locale; + +import com.github.benmanes.caffeine.cache.Caffeine; + +import org.apache.jackrabbit.oak.cache.CacheLIRS; +import org.apache.jackrabbit.oak.cache.api.Cache; +import org.apache.jackrabbit.oak.cache.api.CacheLoader; +import org.apache.jackrabbit.oak.cache.api.LoadingCache; +import org.apache.jackrabbit.oak.cache.api.EvictionListener; +import org.apache.jackrabbit.oak.cache.api.Weigher; +import org.apache.jackrabbit.oak.cache.api.impl.caffeine.CacheComputationException; +import org.apache.jackrabbit.oak.cache.api.impl.caffeine.CaffeineCacheAdapter; +import org.apache.jackrabbit.oak.cache.api.impl.caffeine.CaffeineLoadingCacheAdapter; +import org.apache.jackrabbit.oak.cache.api.impl.lirs.LirsCacheAdapter; +import org.apache.jackrabbit.oak.cache.api.impl.lirs.LirsLoadingCacheAdapter; +import org.jetbrains.annotations.NotNull; + +/** + * Builder for {@link Cache} and {@link LoadingCache} 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 CacheBuilder<K, V> { + + // Common fields + private String module; + private CacheImplementation implementation; + private long maximumWeight = -1; + private long maximumSize = -1; + private Weigher<? super K, ? super V> weigher; + private EvictionListener<? super K, ? super V> removalListener; Review Comment: ```suggestion private EvictionListener<? super K, ? super V> evictionListener; ``` -- 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]
