Skip to content

Commit 42f2a65

Browse files
committed
OAK-12153 : removed guava cache from oak-search
1 parent 1a928a1 commit 42f2a65

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/CacheBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
*/
1717
package org.apache.jackrabbit.oak.cache.api;
1818

19+
import java.time.Clock;
1920
import java.time.Duration;
21+
import java.util.concurrent.TimeUnit;
2022
import java.util.function.Supplier;
2123

2224
import com.github.benmanes.caffeine.cache.Caffeine;
@@ -186,6 +188,18 @@ public CacheBuilder<K, V> ticker(@NotNull Supplier<Long> ticker) {
186188
return this;
187189
}
188190

191+
/**
192+
* Sets the clock used to measure time for expiry and refresh.
193+
* Convenience overload for {@link #ticker(Supplier)}; converts milliseconds to nanoseconds internally.
194+
*
195+
* @param clock the clock to use (must not be null)
196+
* @return this builder
197+
*/
198+
@NotNull
199+
public CacheBuilder<K, V> ticker(@NotNull Clock clock) {
200+
return ticker(() -> TimeUnit.MILLISECONDS.toNanos(clock.millis()));
201+
}
202+
189203
/**
190204
* Builds and returns a cache with no auto-loading behaviour.
191205
*

oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.apache.commons.io.FilenameUtils;
3535
import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
3636
import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
37-
import org.apache.jackrabbit.oak.cache.CacheStats;
37+
import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
3838
import org.apache.jackrabbit.oak.commons.internal.concurrent.ExecutorHelper;
3939
import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard;
4040
import org.apache.jackrabbit.oak.plugins.document.spi.JournalPropertyService;
@@ -686,7 +686,7 @@ private void initializeExtractedTextCache(BundleContext bundleContext, Configura
686686
if (extractedTextProvider != null){
687687
registerExtractedTextProvider(extractedTextProvider);
688688
}
689-
CacheStats stats = extractedTextCache.getCacheStats();
689+
AbstractCacheStats stats = extractedTextCache.getCacheStats();
690690
if (stats != null){
691691
oakRegs.add(registerMBean(whiteboard,
692692
CacheStatsMBean.class, stats,

oak-search/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@
9393
<version>${project.version}</version>
9494
<scope>provided</scope>
9595
</dependency>
96+
<dependency>
97+
<groupId>org.apache.jackrabbit</groupId>
98+
<artifactId>oak-core-spi</artifactId>
99+
<version>${project.version}</version>
100+
<scope>provided</scope>
101+
</dependency>
96102
<dependency>
97103
<groupId>org.apache.jackrabbit</groupId>
98104
<artifactId>oak-store-spi</artifactId>

oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/ExtractedTextCache.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.io.File;
2525
import java.io.FileInputStream;
26+
import java.time.Duration;
2627
import java.io.FileOutputStream;
2728
import java.io.IOException;
2829
import java.util.Map.Entry;
@@ -36,11 +37,12 @@
3637
import java.util.concurrent.TimeUnit;
3738
import java.util.concurrent.TimeoutException;
3839

39-
import org.apache.jackrabbit.guava.common.cache.Cache;
40-
import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
41-
import org.apache.jackrabbit.guava.common.cache.Weigher;
4240
import org.apache.jackrabbit.oak.api.Blob;
43-
import org.apache.jackrabbit.oak.cache.CacheStats;
41+
import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
42+
import org.apache.jackrabbit.oak.cache.api.Cache;
43+
import org.apache.jackrabbit.oak.cache.api.CacheBuilder;
44+
import org.apache.jackrabbit.oak.cache.api.CacheStatsAdapter;
45+
import org.apache.jackrabbit.oak.cache.api.Weigher;
4446
import org.apache.jackrabbit.oak.commons.IOUtils;
4547
import org.apache.jackrabbit.oak.commons.internal.concurrent.ExecutorHelper;
4648
import org.apache.jackrabbit.oak.plugins.index.fulltext.ExtractedText;
@@ -85,7 +87,7 @@ public class ExtractedTextCache {
8587

8688
private final ConcurrentHashMap<String, String> timeoutMap;
8789
private final File indexDir;
88-
private final CacheStats cacheStats;
90+
private final AbstractCacheStats cacheStats;
8991
private final boolean alwaysUsePreExtractedCache;
9092
private volatile ExecutorService executorService;
9193
private volatile int timeoutCount;
@@ -103,13 +105,13 @@ public ExtractedTextCache(long maxWeight, long expiryTimeInSecs, boolean alwaysU
103105
public ExtractedTextCache(long maxWeight, long expiryTimeInSecs, boolean alwaysUsePreExtractedCache,
104106
File indexDir, StatisticsProvider statisticsProvider) {
105107
if (maxWeight > 0) {
106-
cache = CacheBuilder.newBuilder()
108+
cache = CacheBuilder.<String, String>newBuilder()
107109
.weigher(EmpiricalWeigher.INSTANCE)
108110
.maximumWeight(maxWeight)
109-
.expireAfterAccess(expiryTimeInSecs, TimeUnit.SECONDS)
111+
.expireAfterAccess(Duration.ofSeconds(expiryTimeInSecs))
110112
.recordStats()
111113
.build();
112-
cacheStats = new CacheStats(cache, "ExtractedTextCache",
114+
cacheStats = new CacheStatsAdapter(cache, "ExtractedTextCache",
113115
EmpiricalWeigher.INSTANCE, maxWeight);
114116
} else {
115117
cache = null;
@@ -248,7 +250,7 @@ public int getTimeoutCount() {
248250
}
249251

250252
@Nullable
251-
public CacheStats getCacheStats() {
253+
public AbstractCacheStats getCacheStats() {
252254
return cacheStats;
253255
}
254256

0 commit comments

Comments
 (0)