
ru.progrm_jarvis.javacommons.cache.CacheFactory Maven / Gradle / Ivy
package ru.progrm_jarvis.javacommons.cache;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
/**
* Factory used for creation of generic {@link Cache caches}.
*/
public interface CacheFactory {
/**
* Creates a new cache whose keys will be stored {@link java.lang.ref.WeakReference weakly}.
*
* @param type of cache keys
* @param type of cached values
* @return weak keys cache
*/
@NotNull Cache weakKeysCache();
/**
* Creates a new cache whose values will be stored {@link java.lang.ref.WeakReference weakly}.
*
* @param type of cache keys
* @param type of cached values
* @return weak values cache
*/
@NotNull Cache weakValuesCache();
/**
* Creates a new cache whose values will be stored {@link java.lang.ref.SoftReference softly}.
*
* @param type of cache keys
* @param type of cached values
* @return soft values cache
*/
@NotNull Cache softValuesCache();
/**
* Creates a cache factory which always creates {@link Cache#never() no-op caches}.
*
* @return cache factory which always supplies {@link Cache#never() no-op caches}
*/
static @NotNull CacheFactory never() {
return NeverCacheFactory.INSTANCE;
}
/**
* {@link CacheFactory} which always creates {@link Cache#never() no-op caches}.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class NeverCacheFactory implements CacheFactory {
/**
* Singleton instance of this cache factory.
*/
private static final @NotNull CacheFactory INSTANCE = new NeverCacheFactory();
@Override
public @NotNull Cache weakKeysCache() {
return Cache.never();
}
@Override
public @NotNull Cache weakValuesCache() {
return Cache.never();
}
@Override
public @NotNull Cache softValuesCache() {
return Cache.never();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy