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

io.polaris.core.cache.ICache Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.core.cache;

import io.polaris.core.tuple.Ref;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.function.Supplier;

/**
 * @author Qt
 * @since 1.8
 */
public interface ICache {

	@Nullable
	Ref get(@Nonnull K key);

	@Nullable
	default V getIfPresent(@Nonnull K key) {
		Ref ref = get(key);
		return ref == null ? null : ref.get();
	}

	@Nullable
	V get(@Nonnull K key, Supplier loader);

	@Nullable
	default Ref putIfAbsent(@Nonnull K key, @Nullable V value) {
		Ref existingValue = get(key);
		if (existingValue == null) {
			put(key, value);
		}
		return existingValue;
	}

	void put(@Nonnull K key, @Nullable V value);

	default void putAll(Map m) {
		m.forEach((k, v) -> put(k, v));
	}

	void remove(K key);

	void clear();


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy