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

io.github.xanthic.cache.provider.caffeine.CaffeineDelegate Maven / Gradle / Ivy

There is a newer version: 0.6.2
Show newest version
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 map) {
		cache.putAll(map);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy