Package io.github.xanthic.cache.core
Class CacheApiSpec<K,V>
java.lang.Object
io.github.xanthic.cache.core.CacheApiSpec<K,V>
- Type Parameters:
K
- the type of keys that form the cacheV
- the type of values that are contained in the cache
- All Implemented Interfaces:
io.github.xanthic.cache.api.ICacheSpec<K,
V>
public final class CacheApiSpec<K,V>
extends Object
implements io.github.xanthic.cache.api.ICacheSpec<K,V>
Fluent implementation of
ICacheSpec
.
Use process(Consumer)
to obtain validated instances of the spec.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
executor()
executor
(ScheduledExecutorService executor) expiryTime
(Duration expiryTime) io.github.xanthic.cache.api.domain.ExpiryType
expiryType
(io.github.xanthic.cache.api.domain.ExpiryType expiryType) int
hashCode()
highContention
(Boolean highContention) maxSize()
static <K,
V> @NotNull CacheApiSpec <K, V> process
(@NotNull Consumer<CacheApiSpec<K, V>> spec) Constructs a validated implementation ofICacheSpec
.@NotNull io.github.xanthic.cache.api.CacheProvider
provider()
provider
(io.github.xanthic.cache.api.CacheProvider provider) removalListener
(io.github.xanthic.cache.api.RemovalListener<K, V> removalListener) toString()
void
validate()
Ensures the configured specification is valid.
-
Method Details
-
provider
@NotNull public @NotNull io.github.xanthic.cache.api.CacheProvider provider() -
validate
public void validate()Ensures the configured specification is valid.- Throws:
NullPointerException
- if a provider is not specified and no default provider has been setio.github.xanthic.cache.api.exception.MisconfiguredCacheException
- if the cache settings are invalid (e.g., negative max size or expiry time)
-
process
@NotNull public static <K,V> @NotNull CacheApiSpec<K,V> process(@NotNull @NotNull Consumer<CacheApiSpec<K, V>> spec) Constructs a validated implementation ofICacheSpec
.- Type Parameters:
K
- the type of keys that form the cacheV
- the type of values that are contained in the cache- Parameters:
spec
- consumer in which the desired cache settings should be specified- Returns:
- CacheApiSpec
- Throws:
io.github.xanthic.cache.api.exception.NoDefaultCacheImplementationException
- if a provider is not specified and no default provider has been setio.github.xanthic.cache.api.exception.MisconfiguredCacheException
- if the cache settings are invalid (e.g., negative max size or expiry time)
-
maxSize
-
expiryTime
-
expiryType
public io.github.xanthic.cache.api.domain.ExpiryType expiryType() -
removalListener
-
executor
-
highContention
-
provider
- Returns:
this
.
-
maxSize
- Returns:
this
.
-
expiryTime
- Returns:
this
.
-
expiryType
- Returns:
this
.
-
removalListener
public CacheApiSpec<K,V> removalListener(io.github.xanthic.cache.api.RemovalListener<K, V> removalListener) - Returns:
this
.
-
executor
- Returns:
this
.
-
highContention
- Returns:
this
.
-
equals
-
hashCode
public int hashCode() -
toString
-