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 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 of ICacheSpec.
    @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.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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:
      java.lang.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 java.util.function.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 java.lang.Long maxSize()
      Specified by:
      maxSize in interface io.github.xanthic.cache.api.ICacheSpec<K,​V>
    • expiryTime

      public java.time.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 java.util.concurrent.ScheduledExecutorService executor()
      Specified by:
      executor 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​(java.lang.Long maxSize)
      Returns:
      this.
    • expiryTime

      public CacheApiSpec<K,​V> expiryTime​(java.time.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​(java.util.concurrent.ScheduledExecutorService executor)
      Returns:
      this.
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

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

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object