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 cache
V - 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 Details

    • provider

      @NotNull public @NotNull io.github.xanthic.cache.api.CacheProvider provider()
      Specified by:
      provider in interface io.github.xanthic.cache.api.ICacheSpec<K,V>
    • validate

      public void validate()
      Ensures the configured specification is valid.
      Throws:
      NullPointerException - if a provider is not specified and no default provider has been set
      io.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 of ICacheSpec.
      Type Parameters:
      K - the type of keys that form the cache
      V - 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 set
      io.github.xanthic.cache.api.exception.MisconfiguredCacheException - if the cache settings are invalid (e.g., negative max size or expiry time)
    • maxSize

      public Long maxSize()
      Specified by:
      maxSize in interface io.github.xanthic.cache.api.ICacheSpec<K,V>
    • expiryTime

      public Duration expiryTime()
      Specified by:
      expiryTime in interface io.github.xanthic.cache.api.ICacheSpec<K,V>
    • expiryType

      public io.github.xanthic.cache.api.domain.ExpiryType expiryType()
      Specified by:
      expiryType in interface io.github.xanthic.cache.api.ICacheSpec<K,V>
    • removalListener

      public io.github.xanthic.cache.api.RemovalListener<K,V> removalListener()
      Specified by:
      removalListener in interface io.github.xanthic.cache.api.ICacheSpec<K,V>
    • executor

      public ScheduledExecutorService executor()
      Specified by:
      executor in interface io.github.xanthic.cache.api.ICacheSpec<K,V>
    • highContention

      public Boolean highContention()
      Specified by:
      highContention in interface io.github.xanthic.cache.api.ICacheSpec<K,V>
    • provider

      public CacheApiSpec<K,V> provider(io.github.xanthic.cache.api.CacheProvider provider)
      Returns:
      this.
    • maxSize

      public CacheApiSpec<K,V> maxSize(Long maxSize)
      Returns:
      this.
    • expiryTime

      public CacheApiSpec<K,V> expiryTime(Duration expiryTime)
      Returns:
      this.
    • expiryType

      public CacheApiSpec<K,V> expiryType(io.github.xanthic.cache.api.domain.ExpiryType expiryType)
      Returns:
      this.
    • removalListener

      public CacheApiSpec<K,V> removalListener(io.github.xanthic.cache.api.RemovalListener<K,V> removalListener)
      Returns:
      this.
    • executor

      public CacheApiSpec<K,V> executor(ScheduledExecutorService executor)
      Returns:
      this.
    • highContention

      public CacheApiSpec<K,V> highContention(Boolean highContention)
      Returns:
      this.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object