io.sirix.cache.PathSummaryCache Maven / Gradle / Ivy
package io.sirix.cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class PathSummaryCache implements Cache {
private final com.github.benmanes.caffeine.cache.Cache cache;
public PathSummaryCache(final int maxSize) {
cache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterAccess(5, TimeUnit.MINUTES)
.build();
}
@Override
public void clear() {
cache.invalidateAll();
}
@Override
public PathSummaryData get(Integer key) {
return cache.getIfPresent(key);
}
@Override
public void put(Integer key, PathSummaryData value) {
cache.put(key, value);
}
@Override
public void putAll(Map extends Integer, ? extends PathSummaryData> map) {
cache.putAll(map);
}
@Override
public void toSecondCache() {
throw new UnsupportedOperationException();
}
@Override
public Map getAll(Iterable extends Integer> keys) {
return cache.getAllPresent(keys);
}
@Override
public void remove(Integer key) {
cache.invalidate(key);
}
@Override
public void close() {
}
}