org.rapidgraphql.dataloaders.GuavaFutureCache Maven / Gradle / Ivy
package org.rapidgraphql.dataloaders;
import com.google.common.cache.Cache;
import org.dataloader.CacheMap;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class GuavaFutureCache implements CacheMap {
private final Cache> cache;
public GuavaFutureCache(Cache> cache) {
this.cache = cache;
}
@Override
public boolean containsKey(K key) {
return cache.getIfPresent(key) != null;
}
@Override
public CompletableFuture get(K key) {
return cache.getIfPresent(key);
}
@Override
public Collection> getAll() {
return cache.asMap().values().stream().toList();
}
@Override
public CacheMap set(K key, CompletableFuture value) {
cache.put(key, value);
return this;
}
@Override
public CacheMap delete(K key) {
cache.invalidate(key);
return this;
}
@Override
public CacheMap clear() {
cache.invalidateAll();
return this;
}
}