io.github.xanthic.cache.provider.caffeine.CaffeineDelegate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cache-provider-caffeine Show documentation
Show all versions of cache-provider-caffeine Show documentation
Xanthic Provider dependency for Caffeine
package io.github.xanthic.cache.provider.caffeine;
import com.github.benmanes.caffeine.cache.Cache;
import io.github.xanthic.cache.core.delegate.GenericMapCacheDelegate;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.function.Function;
@Value
@EqualsAndHashCode(callSuper = false)
class CaffeineDelegate extends GenericMapCacheDelegate {
Cache cache;
public CaffeineDelegate(Cache cache) {
super(cache.asMap());
this.cache = cache;
}
@Override
public V get(@NotNull K key) {
return cache.getIfPresent(key);
}
@Override
public V computeIfAbsent(@NotNull K key, @NotNull Function computeFunc) {
return cache.get(key, computeFunc);
}
@Override
public void clear() {
cache.invalidateAll();
}
@Override
public long size() {
cache.cleanUp();
return cache.estimatedSize();
}
@Override
public void putAll(@NotNull Map extends K, ? extends V> map) {
cache.putAll(map);
}
}