All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rapidgraphql.dataloaders.GuavaFutureCache Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy