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:
2019-02-16 10:23:52 +01:00
parent 7b00eede86
commit 117ef4ea34
5 changed files with 354 additions and 733 deletions

View File

@@ -13,9 +13,7 @@ import org.lucares.pdb.datastore.ReadException;
import org.lucares.pdb.datastore.WriteException;
import org.lucares.pdb.datastore.internal.DataStore;
import org.lucares.utils.cache.HotEntryCache;
import org.lucares.utils.cache.HotEntryCache.Event;
import org.lucares.utils.cache.HotEntryCache.EventListener;
import org.lucares.utils.cache.HotEntryCache.EventType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,8 +63,8 @@ public class TagsToFile implements AutoCloseable {
private final static class RemovalListener implements EventListener<CacheKey, PdbWriter> {
@Override
public void onEvent(final Event<CacheKey, PdbWriter> event) {
event.getValue().close();
public void evicted(final CacheKey key, final PdbWriter value) {
value.close();
}
}
@@ -76,8 +74,8 @@ public class TagsToFile implements AutoCloseable {
public TagsToFile(final DataStore dataStore) {
this.dataStore = dataStore;
writerCache = new HotEntryCache<>(Duration.ofSeconds(10), "writerCache");
writerCache.addListener(new RemovalListener(), EventType.EVICTED, EventType.REMOVED);
writerCache = new HotEntryCache<>(Duration.ofSeconds(10), 1000);
writerCache.addListener(new RemovalListener());
}
public List<PdbFile> getFilesForQuery(final String query) {