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

jdash.client.cache.InMemoryCache Maven / Gradle / Ivy

package jdash.client.cache;

import jdash.client.request.GDRequest;

import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public final class InMemoryCache implements GDCache {

    private final ConcurrentHashMap map = new ConcurrentHashMap<>();

    @Override
    public Optional retrieve(GDRequest request) {
        Objects.requireNonNull(request);
        return Optional.ofNullable(map.get(request));
    }

    @Override
    public void put(GDRequest request, Object cached) {
        Objects.requireNonNull(request);
        Objects.requireNonNull(cached);
        map.put(request, cached);
    }

    @Override
    public void clear() {
        map.clear();
    }
}