io.sirix.cache.RecordPageCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirix-core Show documentation
Show all versions of sirix-core Show documentation
SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.
package io.sirix.cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.RemovalListener;
import io.sirix.page.KeyValueLeafPage;
import io.sirix.page.PageReference;
import org.checkerframework.checker.nullness.qual.NonNull;
import io.sirix.page.interfaces.Page;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public final class RecordPageCache implements Cache {
private final com.github.benmanes.caffeine.cache.Cache pageCache;
public RecordPageCache(final int maxSize) {
final RemovalListener removalListener =
(PageReference key, KeyValueLeafPage value, RemovalCause cause) -> {
key.setPage(null);
// if (value instanceof KeyValueLeafPage keyValueLeafPage) {
// keyValueLeafPage.clearPage();
// }
};
pageCache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterAccess(5, TimeUnit.MINUTES)
.scheduler(scheduler)
.removalListener(removalListener)
.build();
}
@Override
public void clear() {
pageCache.invalidateAll();
}
@Override
public KeyValueLeafPage get(PageReference key) {
var keyValueLeafPage = pageCache.getIfPresent(key);
// if (keyValueLeafPage != null) {
// keyValueLeafPage = new KeyValueLeafPage(keyValueLeafPage);
// }
return keyValueLeafPage;
}
@Override
public void put(PageReference key, @NonNull KeyValueLeafPage value) {
pageCache.put(key, value);
}
@Override
public void putAll(Map extends PageReference, ? extends KeyValueLeafPage> map) {
pageCache.putAll(map);
}
@Override
public void toSecondCache() {
throw new UnsupportedOperationException();
}
@Override
public Map getAll(Iterable extends PageReference> keys) {
return pageCache.getAllPresent(keys);
}
@Override
public void remove(PageReference key) {
pageCache.invalidate(key);
}
@Override
public void close() {
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy