use guava's cache as implementation for the HotEntryCache
My own implementation was faster, but was not able to implement a size limitation.
This commit is contained in:
@@ -12,6 +12,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.lucares.collections.LongList;
|
||||
@@ -71,8 +72,7 @@ public class DataStore implements AutoCloseable {
|
||||
|
||||
// A Doc will never be changed once it is created. Therefore we can cache them
|
||||
// easily.
|
||||
private final HotEntryCache<Long, Doc> docIdToDocCache = new HotEntryCache<>(Duration.ofSeconds(5),
|
||||
"docIdToDocCache");
|
||||
private final HotEntryCache<Long, Doc> docIdToDocCache = new HotEntryCache<>(Duration.ofMillis(30), 100_000);
|
||||
|
||||
private final DiskStorage diskStorage;
|
||||
private final Path diskStorageFilePath;
|
||||
@@ -262,13 +262,17 @@ public class DataStore implements AutoCloseable {
|
||||
}
|
||||
|
||||
private Doc getDocByDocId(final Long docId) {
|
||||
return docIdToDocCache.putIfAbsent(docId, k -> {
|
||||
try {
|
||||
return docIdToDoc.getValue(k);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return docIdToDocCache.putIfAbsent(docId, () -> {
|
||||
try {
|
||||
return docIdToDoc.getValue(docId);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
});
|
||||
} catch (final ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user