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

io.github.xanthic.cache.provider.androidx.LruDelegate Maven / Gradle / Ivy

package io.github.xanthic.cache.provider.androidx;

import androidx.collection.LruCache;
import io.github.xanthic.cache.core.AbstractCache;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Value;
import org.jetbrains.annotations.NotNull;

import java.util.function.BiConsumer;

@Value
@Getter(AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false)
class LruDelegate extends AbstractCache {
	LruCache cache;

	@Override
	public V get(@NotNull K key) {
		// note: underlying operations are synchronized on same object
		return cache.get(key);
	}

	@Override
	public V put(@NotNull K key, @NotNull V value) {
		return cache.put(key, value);
	}

	@Override
	public V remove(@NotNull K key) {
		return cache.remove(key);
	}

	@Override
	public void clear() {
		cache.evictAll();
	}

	@Override
	public long size() {
		return cache.size();
	}

	@Override
	public void forEach(@NotNull BiConsumer action) {
		cache.snapshot().forEach(action);
	}

	@NotNull
	@Override
	protected Object getLock() {
		return this.cache;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy