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 java.lang.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 Type Method Description boolean
equals(java.lang.Object o)
java.util.concurrent.ScheduledExecutorService
executor()
CacheApiSpec<K,V>
executor(java.util.concurrent.ScheduledExecutorService executor)
java.time.Duration
expiryTime()
CacheApiSpec<K,V>
expiryTime(java.time.Duration expiryTime)
io.github.xanthic.cache.api.domain.ExpiryType
expiryType()
CacheApiSpec<K,V>
expiryType(io.github.xanthic.cache.api.domain.ExpiryType expiryType)
int
hashCode()
java.lang.Long
maxSize()
CacheApiSpec<K,V>
maxSize(java.lang.Long maxSize)
static <K, V> @NotNull CacheApiSpec<K,V>
process(@NotNull java.util.function.Consumer<CacheApiSpec<K,V>> spec)
Constructs a validated implementation ofICacheSpec
.@NotNull io.github.xanthic.cache.api.CacheProvider
provider()
CacheApiSpec<K,V>
provider(io.github.xanthic.cache.api.CacheProvider provider)
io.github.xanthic.cache.api.RemovalListener<K,V>
removalListener()
CacheApiSpec<K,V>
removalListener(io.github.xanthic.cache.api.RemovalListener<K,V> removalListener)
java.lang.String
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:
java.lang.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 java.util.function.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
public java.lang.Long maxSize() -
expiryTime
public java.time.Duration expiryTime() -
expiryType
public io.github.xanthic.cache.api.domain.ExpiryType expiryType() -
removalListener
-
executor
public java.util.concurrent.ScheduledExecutorService executor() -
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
.
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-